teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

誤字

2019/09/21 07:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -196,16 +196,6 @@
196
196
  cTop = $c.offset().top,
197
197
  c_contentTop = $c.find('.content').offset().top;
198
198
 
199
- console.log($a);
200
- console.log($b);
201
- console.log($c);
202
- console.log(aTop);
203
- console.log(a_contentTop);
204
- console.log(bTop);
205
- console.log(b_contentTop);
206
- console.log(cTop);
207
- console.log(c_contentTop);
208
-
209
199
  $('#next_a').on('click', function() {
210
200
  $('body,html').animate({
211
201
  scrollTop: aTop

1

追記

2019/09/21 07:14

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -79,4 +79,188 @@
79
79
 
80
80
  }, 200);
81
81
  コード
82
- ```
82
+ ```
83
+
84
+ ### ※追記
85
+
86
+ ```html
87
+ <!DOCTYPE html>
88
+ <html lang="ja">
89
+
90
+ <head>
91
+ <meta charset="utf-8">
92
+ <title>TEST</title>
93
+
94
+ <style>
95
+ body {
96
+ margin: 0;
97
+ }
98
+
99
+ .btn,
100
+ .first_btn {
101
+ position: relative;
102
+ }
103
+
104
+ #next_a,
105
+ #next_b,
106
+ #next_c,
107
+ #top {
108
+ font-size: 25px;
109
+ cursor: pointer;
110
+ position: absolute;
111
+ bottom: 50px;
112
+ left: 50%;
113
+ margin-left: -25px;
114
+ }
115
+
116
+ .title,
117
+ .content {
118
+ display: flex;
119
+ justify-content: center;
120
+ align-items: center;
121
+ }
122
+
123
+ .title {
124
+ font-size: 25px;
125
+ background: #000;
126
+ color: #fff;
127
+ }
128
+
129
+ .content {
130
+ font-size: 20px;
131
+ background: #eee;
132
+ }
133
+ </style>
134
+
135
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
136
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
137
+
138
+ </head>
139
+
140
+ <body>
141
+
142
+ <div class="first_btn">
143
+ <div id="next_a">次へ</div>
144
+ </div>
145
+ <section id="section_a">
146
+ <div class="title">
147
+ <h2>a</h2>
148
+ </div>
149
+ <div class="content">
150
+ <h3>ここに内容</h3>
151
+ </div>
152
+ <div class="btn">
153
+ <div id="next_b">次へ</div>
154
+ </div>
155
+ </section>
156
+ <section id="section_b">
157
+ <div class=title>
158
+ <h2>b</h2>
159
+ </div>
160
+ <div class="content">
161
+ <h2>ここに内容</h2>
162
+ </div>
163
+ <div class="btn">
164
+ <div id="next_c">次へ</div>
165
+ </div>
166
+ </section>
167
+ <section id="section_c">
168
+ <div class="title">
169
+ <h2>c</h2>
170
+ </div>
171
+ <div class="content">
172
+ <h2>ここに内容</h2>
173
+ </div>
174
+ <div class="btn">
175
+ <div id="top">戻る</div>
176
+ </div>
177
+ </section>
178
+
179
+ <script>
180
+ var resizeTimer = null;
181
+ $(window).on('load resize', function() {
182
+ clearTimeout(resizeTimer);
183
+ resizeTimer = setTimeout(function() {
184
+
185
+ var hSize = $(this).height();
186
+ $('.first_btn,.title,.content').height(hSize);
187
+
188
+
189
+ var $a = $('#section_a'),
190
+ $b = $('#section_b'),
191
+ $c = $('#section_c'),
192
+ aTop = $a.offset().top,
193
+ a_contentTop = $a.find('.content').offset().top,
194
+ bTop = $b.offset().top,
195
+ b_contentTop = $b.find('.content').offset().top,
196
+ cTop = $c.offset().top,
197
+ c_contentTop = $c.find('.content').offset().top;
198
+
199
+ console.log($a);
200
+ console.log($b);
201
+ console.log($c);
202
+ console.log(aTop);
203
+ console.log(a_contentTop);
204
+ console.log(bTop);
205
+ console.log(b_contentTop);
206
+ console.log(cTop);
207
+ console.log(c_contentTop);
208
+
209
+ $('#next_a').on('click', function() {
210
+ $('body,html').animate({
211
+ scrollTop: aTop
212
+ }, 800, autoscroll_a);
213
+ });
214
+
215
+ $('#next_b').on('click', function() {
216
+ $('body,html').animate({
217
+ scrollTop: bTop
218
+ }, 800, autoscroll_b);
219
+ });
220
+
221
+ $('#next_c').on('click', function() {
222
+ $('body,html').animate({
223
+ scrollTop: cTop
224
+ }, 800, autoscroll_c);
225
+ });
226
+
227
+ $('#top').on('click', function() {
228
+ $('body,html').animate({
229
+ scrollTop: 0
230
+ }, 800);
231
+ });
232
+
233
+ function autoscroll_a() {
234
+ setTimeout(function() {
235
+ $('body,html').animate({
236
+ scrollTop: a_contentTop
237
+ }, 300);
238
+ }, 800);
239
+ }
240
+
241
+ function autoscroll_b() {
242
+ setTimeout(function() {
243
+ $('body,html').animate({
244
+ scrollTop: b_contentTop
245
+ }, 300);
246
+ }, 800);
247
+ }
248
+
249
+ function autoscroll_c() {
250
+ setTimeout(function() {
251
+ $('body,html').animate({
252
+ scrollTop: c_contentTop
253
+ }, 300);
254
+ }, 800);
255
+ }
256
+
257
+ }, 200);
258
+ });
259
+ </script>
260
+ </body></html>
261
+ コード
262
+ ```
263
+
264
+ ※最初のjQueryのコードを少し書き変えました。(基本的なところは変えていません)
265
+ 上記のコードを見て頂けると分るかと思うのですが、
266
+ 質問の内容の通り、resizeするとスクロールの挙動がおかしくなります。