[英]Creating a slideshow with left to right animation?
I have the following code 我有以下代码
$(function(){ setInterval(function () { $('#slider').animate({left: 0}, 500, function () { $('#slider img:first-child').appendTo('#slider'); $('#slider img').css('left', ''); }); }, 1000); });
#slider { position: relative; overflow: hidden; margin: 20px auto; width: 500px; height: 300px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="slider"> <img src="http://www.gettyimages.in/CMS/StaticContent/1391099215267_hero2.jpg"></img> <img src="http://www.gettyimages.in/CMS/Pages/RoyaltyFree/StaticContent/109720793.jpg"></img> <img src="http://www.gettyimages.in/CMS/Pages/RoyaltyFree/StaticContent/108114205.jpg"></img> </div>
Images are switched but not sliding they just replace each other. 图像被切换但没有滑动,它们只是彼此替换。 What am I doing wrong?
我究竟做错了什么?
replace this line 替换这条线
$('#slider img').css('left', '');
with this 有了这个
$('#slider').css('left', '0');
fiddle here : https://jsfiddle.net/nu5j2dyr/ 在这里提琴: https : //jsfiddle.net/nu5j2dyr/
another fiddle for sliding anmation: https://jsfiddle.net/88u56y9h/1/ 滑动动画的另一个小提琴: https ://jsfiddle.net/88u56y9h/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.