回答編集履歴

2

追記です

2018/11/04 18:26

投稿

akihiro3
akihiro3

スコア955

test CHANGED
@@ -77,3 +77,257 @@
77
77
  ```
78
78
 
79
79
  良ければこちらも参考にしてください
80
+
81
+ コード追記
82
+
83
+ ---
84
+
85
+ ```html
86
+
87
+ <!DOCTYPE html>
88
+
89
+ <html lang="ja" dir="ltr">
90
+
91
+ <head>
92
+
93
+ <meta charset="utf-8">
94
+
95
+ <title>test</title>
96
+
97
+ <style media="screen">
98
+
99
+ * {
100
+
101
+ margin: 0px;
102
+
103
+ padding: 0px;
104
+
105
+ }
106
+
107
+
108
+
109
+ .container {
110
+
111
+ width: 340px;
112
+
113
+ height: 140px;
114
+
115
+ margin: 50px auto;
116
+
117
+ border: 1px solid #faf;
118
+
119
+ }
120
+
121
+
122
+
123
+ .circles {
124
+
125
+ height: 140px;
126
+
127
+ position: relative;
128
+
129
+ }
130
+
131
+
132
+
133
+ .circle {
134
+
135
+ display: inline-block;
136
+
137
+ position:absolute;
138
+
139
+ }
140
+
141
+
142
+
143
+ .red {
144
+
145
+ background: #f00;
146
+
147
+ width: 100px;
148
+
149
+ height: 100px;
150
+
151
+ border: 1px solid #000;
152
+
153
+ border-radius: 50%;
154
+
155
+ top: 20px;
156
+
157
+ left: 20px;
158
+
159
+ }
160
+
161
+
162
+
163
+ .green {
164
+
165
+ background: #0f0;
166
+
167
+ width: 30px;
168
+
169
+ height: 30px;
170
+
171
+ border: 1px solid #000;
172
+
173
+ border-radius: 50%;
174
+
175
+ top: 20px;
176
+
177
+ left: 50%;
178
+
179
+ }
180
+
181
+
182
+
183
+ .yellow {
184
+
185
+ background: #ff0;
186
+
187
+ width: 50px;
188
+
189
+ height: 50px;
190
+
191
+ border: 1px solid #000;
192
+
193
+ border-radius: 50%;
194
+
195
+ bottom: 20px;
196
+
197
+ right: 20px;
198
+
199
+ }
200
+
201
+
202
+
203
+ .btn {
204
+
205
+ background: #000;
206
+
207
+ width: 20px;
208
+
209
+ height: 20px;
210
+
211
+ border: none;
212
+
213
+ border-radius: 50%;
214
+
215
+ color: #fff;
216
+
217
+ line-height: 20px;
218
+
219
+ position: absolute;
220
+
221
+ bottom: 30px;
222
+
223
+ left: 50%;
224
+
225
+ }
226
+
227
+ </style>
228
+
229
+ <link rel="stylesheet" href="./test.css">
230
+
231
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
232
+
233
+ </head>
234
+
235
+ <body>
236
+
237
+ <div class="container">
238
+
239
+ <ul class="circles">
240
+
241
+ <li class="circle red"></li>
242
+
243
+ <li class="circle green"></li>
244
+
245
+ <li class="circle yellow"></li>
246
+
247
+ <button type="button" class="btn">◀</button>
248
+
249
+ </ul>
250
+
251
+ </div>
252
+
253
+
254
+
255
+ </div>
256
+
257
+ <script type="text/javascript">
258
+
259
+ $(function() {
260
+
261
+ var circle = $('.circle');
262
+
263
+
264
+
265
+ $('.btn').click(function() {
266
+
267
+ $('.circle').each(function(i) { // 兄弟要素に繰り返し処理
268
+
269
+ if (i == circle.length - 1) { // html上で次の要素が無い時
270
+
271
+ var next = circle.eq(0).position(); // 次の要素の座標を取得
272
+
273
+ var width = circle.width(); // 次の要素の幅を取得
274
+
275
+ var height = circle.height(); // 次の要素の高さを取得
276
+
277
+
278
+
279
+ $(this).animate({
280
+
281
+ 'top': next.top, // 移動先のy座標
282
+
283
+ 'left': next.left, // 移動先のx座標
284
+
285
+ 'width': width, // 移動先での幅指定
286
+
287
+ 'height': height, // 移動先での高さ指定
288
+
289
+ },1000) // 1000ミリ秒(1秒)の速さで変化
290
+
291
+
292
+
293
+ } else { // html上で次の要素がある時
294
+
295
+ var next = $(this).next().position(); // 次の要素の座標を取得
296
+
297
+ var width = $(this).next().width(); // 次の要素の幅を取得
298
+
299
+ var height = $(this).next().height(); // 次の要素の高さを取得
300
+
301
+
302
+
303
+ $(this).animate({
304
+
305
+ 'top': next.top, // 移動先のy座標
306
+
307
+ 'left': next.left, // 移動先のx座標
308
+
309
+ 'width': width, // 移動先での幅指定
310
+
311
+ 'height': height, // 移動先での高さ指定
312
+
313
+ },1000) // 1000ミリ秒(1秒)の速さで変化
314
+
315
+
316
+
317
+ }
318
+
319
+ });
320
+
321
+ });
322
+
323
+
324
+
325
+ });
326
+
327
+ </script>
328
+
329
+ </body>
330
+
331
+ </html>
332
+
333
+ ```

1

説明不足かもしれなかったので少し足しました

2018/11/04 18:26

投稿

akihiro3
akihiro3

スコア955

test CHANGED
@@ -17,3 +17,63 @@
17
17
 
18
18
 
19
19
  よければ参考にしてみてください
20
+
21
+
22
+
23
+ 追記
24
+
25
+ ---
26
+
27
+ 補足とコード確認しました
28
+
29
+
30
+
31
+ ・サイズ変更の方法です
32
+
33
+ [画像サイズの変更](https://javascript.programmer-reference.com/js-image-resize/)
34
+
35
+ [jsでCSSの変更](https://sterfield.co.jp/designer/javascript%E3%81%A7css%E3%82%92%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/)
36
+
37
+
38
+
39
+ 試してない事は上の方法などを参考にしてみてください
40
+
41
+ あとsrc[59]は連続した数字がループ内で取得できるか?(「i」以外で)
42
+
43
+ というのが分かれば良いですか?
44
+
45
+ ```js
46
+
47
+ var length = 59;
48
+
49
+ var src = 59;
50
+
51
+ function result() {
52
+
53
+ console.log('photos[' + i + ']');
54
+
55
+ console.log('src[' + src + ']');
56
+
57
+ }
58
+
59
+
60
+
61
+ for ( var i = 0; i < length; i++ ) {
62
+
63
+ if ( i == length - 1 ) {
64
+
65
+ src = 3;
66
+
67
+ result();
68
+
69
+ } else {
70
+
71
+ src--;
72
+
73
+ result();
74
+
75
+ }
76
+
77
+ ```
78
+
79
+ 良ければこちらも参考にしてください