回答編集履歴

1

chousei

2019/08/27 10:55

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1,3 +1,83 @@
1
1
  クリック時にカスタムデータかなにかにフラグをたてておいて
2
2
 
3
3
  フラグのありなしで削除と追加をいれかえるとかですかね
4
+
5
+
6
+
7
+ # sample
8
+
9
+
10
+
11
+ たとえばこんな感じ
12
+
13
+ ```javascript
14
+
15
+ <style>
16
+
17
+ body{margin:0px;padding:0px}
18
+
19
+ #hamburger{position:fixed;z-index:1;height:1.5em;background-Color:gray;width:100%;}
20
+
21
+ #content{height:999px;margin-top:1.5em;position:absolute;};
22
+
23
+ </style>
24
+
25
+
26
+
27
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
28
+
29
+ <script>
30
+
31
+ $(function(){
32
+
33
+ $('#hamburger').on('click',function(e){
34
+
35
+ var flg=$(this).data('flg')||false;
36
+
37
+ $(this).data('flg',!flg);
38
+
39
+ scrollpos = $(window).scrollTop();
40
+
41
+ if(flg){
42
+
43
+ $('#content').css({'margin-top': '','position': ''});
44
+
45
+ }else{
46
+
47
+ $('#content').css({'margin-top': -scrollpos,'position': 'fixed'});
48
+
49
+ }
50
+
51
+ })
52
+
53
+ });
54
+
55
+ </script>
56
+
57
+ <div id="hamburger">hamburger</div>
58
+
59
+ <div id="content">
60
+
61
+ 1<br><br><br><br><br>
62
+
63
+ 2<br><br><br><br><br>
64
+
65
+ 3<br><br><br><br><br>
66
+
67
+ 4<br><br><br><br><br>
68
+
69
+ 5<br><br><br><br><br>
70
+
71
+ 6<br><br><br><br><br>
72
+
73
+ 7<br><br><br><br><br>
74
+
75
+ 8<br><br><br><br><br>
76
+
77
+ 9<br><br><br><br><br>
78
+
79
+ 10<br><br><br><br><br>
80
+
81
+ </div>
82
+
83
+ ```