質問編集履歴

1

実際のソースを追加しました

2017/02/02 02:06

投稿

KOTP
KOTP

スコア10

test CHANGED
File without changes
test CHANGED
@@ -69,3 +69,129 @@
69
69
 
70
70
 
71
71
  何かヒントをいただければ幸いです。
72
+
73
+
74
+
75
+ ーーーー追記ーーーーーー
76
+
77
+
78
+
79
+ スクリプト全体は以下の通りです。
80
+
81
+ ```
82
+
83
+ <script>
84
+
85
+ var $win = $(window);
86
+
87
+ $win.scroll(function() {
88
+
89
+ var h = $('.eye_catch').innerHeight();//高さを取得(h)
90
+
91
+ if ($(this).scrollTop() > h){ //hまできたらアクション
92
+
93
+ $('header').addClass("sticky");
94
+
95
+ }
96
+
97
+ else{
98
+
99
+ $('header').removeClass("sticky");
100
+
101
+ }
102
+
103
+ if('ontouchstart' in window) {
104
+
105
+ this.$win.bind('touchmove', function () {
106
+
107
+ var h = $('.eye_catch').innerHeight();//高さを取得(h)
108
+
109
+ if ($(this).scrollTop() > h){ //hまできたらアクション
110
+
111
+ $('header').addClass("sticky");
112
+
113
+ }
114
+
115
+ else{
116
+
117
+ $('header').removeClass("sticky");
118
+
119
+ }
120
+
121
+ });
122
+
123
+ }
124
+
125
+ });
126
+
127
+ </script>
128
+
129
+ ```
130
+
131
+ こちらのパターンも試してみました。
132
+
133
+ ```<script>
134
+
135
+ $(function(){
136
+
137
+ var $header = $('.header');
138
+
139
+ var h = $('.eye_catch').innerHeight();
140
+
141
+ var $wrap = $('#wrap');
142
+
143
+ var $offsetTop = $header.offset().top;
144
+
145
+ var $fixedMenu = function(){
146
+
147
+ if($(window).scrollTop()>$offsetTop){
148
+
149
+ $header.css({
150
+
151
+ 'position':'fixed',
152
+
153
+ 'top':'0',
154
+
155
+ 'z-index':'999'
156
+
157
+ });
158
+
159
+ $wrap.css({
160
+
161
+ 'padding-top':'55px'
162
+
163
+ });
164
+
165
+ }else{
166
+
167
+ $header.css({
168
+
169
+ 'position':'',
170
+
171
+ 'top':'',
172
+
173
+ 'z-index':''
174
+
175
+ })
176
+
177
+ $wrap.css({
178
+
179
+ 'padding-top':''
180
+
181
+ });
182
+
183
+ }
184
+
185
+ }
186
+
187
+ $(window).scroll($fixedMenu);
188
+
189
+ jQuery('body').bind('touchmove',$fixedMenu);
190
+
191
+ });
192
+
193
+ </script>
194
+
195
+ コード
196
+
197
+ ```