回答編集履歴
2
追記です
answer
CHANGED
@@ -37,4 +37,131 @@
|
|
37
37
|
result();
|
38
38
|
}
|
39
39
|
```
|
40
|
-
良ければこちらも参考にしてください
|
40
|
+
良ければこちらも参考にしてください
|
41
|
+
コード追記
|
42
|
+
---
|
43
|
+
```html
|
44
|
+
<!DOCTYPE html>
|
45
|
+
<html lang="ja" dir="ltr">
|
46
|
+
<head>
|
47
|
+
<meta charset="utf-8">
|
48
|
+
<title>test</title>
|
49
|
+
<style media="screen">
|
50
|
+
* {
|
51
|
+
margin: 0px;
|
52
|
+
padding: 0px;
|
53
|
+
}
|
54
|
+
|
55
|
+
.container {
|
56
|
+
width: 340px;
|
57
|
+
height: 140px;
|
58
|
+
margin: 50px auto;
|
59
|
+
border: 1px solid #faf;
|
60
|
+
}
|
61
|
+
|
62
|
+
.circles {
|
63
|
+
height: 140px;
|
64
|
+
position: relative;
|
65
|
+
}
|
66
|
+
|
67
|
+
.circle {
|
68
|
+
display: inline-block;
|
69
|
+
position:absolute;
|
70
|
+
}
|
71
|
+
|
72
|
+
.red {
|
73
|
+
background: #f00;
|
74
|
+
width: 100px;
|
75
|
+
height: 100px;
|
76
|
+
border: 1px solid #000;
|
77
|
+
border-radius: 50%;
|
78
|
+
top: 20px;
|
79
|
+
left: 20px;
|
80
|
+
}
|
81
|
+
|
82
|
+
.green {
|
83
|
+
background: #0f0;
|
84
|
+
width: 30px;
|
85
|
+
height: 30px;
|
86
|
+
border: 1px solid #000;
|
87
|
+
border-radius: 50%;
|
88
|
+
top: 20px;
|
89
|
+
left: 50%;
|
90
|
+
}
|
91
|
+
|
92
|
+
.yellow {
|
93
|
+
background: #ff0;
|
94
|
+
width: 50px;
|
95
|
+
height: 50px;
|
96
|
+
border: 1px solid #000;
|
97
|
+
border-radius: 50%;
|
98
|
+
bottom: 20px;
|
99
|
+
right: 20px;
|
100
|
+
}
|
101
|
+
|
102
|
+
.btn {
|
103
|
+
background: #000;
|
104
|
+
width: 20px;
|
105
|
+
height: 20px;
|
106
|
+
border: none;
|
107
|
+
border-radius: 50%;
|
108
|
+
color: #fff;
|
109
|
+
line-height: 20px;
|
110
|
+
position: absolute;
|
111
|
+
bottom: 30px;
|
112
|
+
left: 50%;
|
113
|
+
}
|
114
|
+
</style>
|
115
|
+
<link rel="stylesheet" href="./test.css">
|
116
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
117
|
+
</head>
|
118
|
+
<body>
|
119
|
+
<div class="container">
|
120
|
+
<ul class="circles">
|
121
|
+
<li class="circle red"></li>
|
122
|
+
<li class="circle green"></li>
|
123
|
+
<li class="circle yellow"></li>
|
124
|
+
<button type="button" class="btn">◀</button>
|
125
|
+
</ul>
|
126
|
+
</div>
|
127
|
+
|
128
|
+
</div>
|
129
|
+
<script type="text/javascript">
|
130
|
+
$(function() {
|
131
|
+
var circle = $('.circle');
|
132
|
+
|
133
|
+
$('.btn').click(function() {
|
134
|
+
$('.circle').each(function(i) { // 兄弟要素に繰り返し処理
|
135
|
+
if (i == circle.length - 1) { // html上で次の要素が無い時
|
136
|
+
var next = circle.eq(0).position(); // 次の要素の座標を取得
|
137
|
+
var width = circle.width(); // 次の要素の幅を取得
|
138
|
+
var height = circle.height(); // 次の要素の高さを取得
|
139
|
+
|
140
|
+
$(this).animate({
|
141
|
+
'top': next.top, // 移動先のy座標
|
142
|
+
'left': next.left, // 移動先のx座標
|
143
|
+
'width': width, // 移動先での幅指定
|
144
|
+
'height': height, // 移動先での高さ指定
|
145
|
+
},1000) // 1000ミリ秒(1秒)の速さで変化
|
146
|
+
|
147
|
+
} else { // html上で次の要素がある時
|
148
|
+
var next = $(this).next().position(); // 次の要素の座標を取得
|
149
|
+
var width = $(this).next().width(); // 次の要素の幅を取得
|
150
|
+
var height = $(this).next().height(); // 次の要素の高さを取得
|
151
|
+
|
152
|
+
$(this).animate({
|
153
|
+
'top': next.top, // 移動先のy座標
|
154
|
+
'left': next.left, // 移動先のx座標
|
155
|
+
'width': width, // 移動先での幅指定
|
156
|
+
'height': height, // 移動先での高さ指定
|
157
|
+
},1000) // 1000ミリ秒(1秒)の速さで変化
|
158
|
+
|
159
|
+
}
|
160
|
+
});
|
161
|
+
});
|
162
|
+
|
163
|
+
});
|
164
|
+
</script>
|
165
|
+
</body>
|
166
|
+
</html>
|
167
|
+
```
|
1
説明不足かもしれなかったので少し足しました
answer
CHANGED
@@ -7,4 +7,34 @@
|
|
7
7
|
・他だと、こんなのもありました
|
8
8
|
[画面内でのオブジェクトの移動](http://www.myu.ac.jp/~akizuki/sct/object_ns/index.html)
|
9
9
|
|
10
|
-
よければ参考にしてみてください
|
10
|
+
よければ参考にしてみてください
|
11
|
+
|
12
|
+
追記
|
13
|
+
---
|
14
|
+
補足とコード確認しました
|
15
|
+
|
16
|
+
・サイズ変更の方法です
|
17
|
+
[画像サイズの変更](https://javascript.programmer-reference.com/js-image-resize/)
|
18
|
+
[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/)
|
19
|
+
|
20
|
+
試してない事は上の方法などを参考にしてみてください
|
21
|
+
あとsrc[59]は連続した数字がループ内で取得できるか?(「i」以外で)
|
22
|
+
というのが分かれば良いですか?
|
23
|
+
```js
|
24
|
+
var length = 59;
|
25
|
+
var src = 59;
|
26
|
+
function result() {
|
27
|
+
console.log('photos[' + i + ']');
|
28
|
+
console.log('src[' + src + ']');
|
29
|
+
}
|
30
|
+
|
31
|
+
for ( var i = 0; i < length; i++ ) {
|
32
|
+
if ( i == length - 1 ) {
|
33
|
+
src = 3;
|
34
|
+
result();
|
35
|
+
} else {
|
36
|
+
src--;
|
37
|
+
result();
|
38
|
+
}
|
39
|
+
```
|
40
|
+
良ければこちらも参考にしてください
|