这样写会出错么
function animate(num){ var newLeft = parseInt(list.style.left) + num list.style.left = newLeft + 'px'; if(newLeft > 0){ list.style.left = -2400 + 'px'; }else if(newLeft < -2400){ list.style.left = 0; } } next.onclick = function(){ animate(-num); } prev.onclick = function(){ animate(num); }
<div id="list" style="left:0px"> <img src="img/1.jpg" alt="pic"> <img src="img/2.jpg" alt="pic"> <img src="img/3.jpg" alt="pic"> <img src="img/4.jpg" alt="pic"> <img src="img/5.jpg" alt="pic"> </div>
直接这样貌似也可以啊,不用模拟第一个跟最后一个图好像点起来也没问题