回答編集履歴
1
ついき
test
CHANGED
@@ -161,3 +161,71 @@
|
|
161
161
|
|
162
162
|
|
163
163
|
```
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
# 最後の次は最初、最初の前は最後
|
168
|
+
|
169
|
+
```javascript
|
170
|
+
|
171
|
+
$(function(){
|
172
|
+
|
173
|
+
var left=0;
|
174
|
+
|
175
|
+
var current=0;
|
176
|
+
|
177
|
+
$('.next').on('click',function(){
|
178
|
+
|
179
|
+
var w=$('.slider-list img').eq(current).width();
|
180
|
+
|
181
|
+
var len=$('.slider-list img').length;
|
182
|
+
|
183
|
+
current++;
|
184
|
+
|
185
|
+
if(current<len){
|
186
|
+
|
187
|
+
left-=w;
|
188
|
+
|
189
|
+
}else{
|
190
|
+
|
191
|
+
left =0;
|
192
|
+
|
193
|
+
current=0;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
$('.slider-list').animate({left:left});
|
198
|
+
|
199
|
+
});
|
200
|
+
|
201
|
+
$('.prev').on('click',function(){
|
202
|
+
|
203
|
+
var w=$('.slider-list img').eq(current).width();
|
204
|
+
|
205
|
+
var len=$('.slider-list img').length;
|
206
|
+
|
207
|
+
current--;
|
208
|
+
|
209
|
+
if(current>=0){
|
210
|
+
|
211
|
+
left+=w;
|
212
|
+
|
213
|
+
}else{
|
214
|
+
|
215
|
+
left=-$('.slider-list img:not(:last)').map(function(){
|
216
|
+
|
217
|
+
return $(this).width();
|
218
|
+
|
219
|
+
}).get().reduce((x,y)=>x+y);
|
220
|
+
|
221
|
+
current=len-1;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
$('.slider-list').animate({left:left});
|
226
|
+
|
227
|
+
});
|
228
|
+
|
229
|
+
});
|
230
|
+
|
231
|
+
```
|