滑块不会向左边缘工作:0

时间:2016-03-08 16:52:07

标签: javascript jquery jquery-animate

我正在研究jQuery,我在下面做了这个简单的代码来动画三个图像,如幻灯片。问题是,当最后一个图像被淋浴时,代码应该返回执行margin-left 0并再次启动幻灯片,但它不起作用。



$(function() {

			var width = 809;
			var animationSpeed = 1000;
			var pause = 1000;	
			var currentSlide = 1;

			var $slideContainer = $("#slideshow .slides");
			var $slide = $("#slideshow .slide");


			setInterval(function() {			
			$slideContainer.animate({ 'margin-left': '-='+width }, animationSpeed, function(){
				$("#console").html("Posicao: "+currentSlide);
				currentSlide++;				
				if (currentSlide === $slide.length){
					currentSlide = 1;
					$slideContainer.css('margin-left: ', 0);
				}	
			});
		}, pause);	
		});

		#slideshow {			
			width: 809px;
			height: 449px;
			overflow: hidden;
		}
		#slideshow .slides {
			display: block;
			width: 3236px;
			height: 449px;
			margin: 0;
			padding: 0;
		}
		#slideshow .slide {
			float: left;
			list-style-type: none;
			width: 809px;
			height: 449px;

<div id="slideshow">
<ul class="slides">
	<li class="slide"><img src="teste1.jpg" /></li>
	<li class="slide"><img src="teste2.jpg" /></li>
	<li class="slide"><img src="teste3.jpg" /></li>
	<li class="slide"><img src="teste1.jpg" /></li>
</ul>

</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

$slideContainer.css('margin-left: ', 0); is incorrect
$slideContainer.css('margin-left', 0); correct

https://api.jquery.com/css/