[英]Simple slideshow with jQuery (won't go beyond first child)
I've got a simple slideshow, but it only slides to the second image: 我有一个简单的幻灯片,但它只滑到第二张图片:
http://jsfiddle.net/tmyie/RCQUx/1/ http://jsfiddle.net/tmyie/RCQUx/1/
$('.next').click(function(){
$('.img:first').fadeOut(function(){
$(this).next().fadeIn();
});
});
I'm aware I need to use a $(this)
selector. 我知道我需要使用$(this)
选择器。 Is there a way to do so, without traversing from .next
? 有没有办法从.next
遍历? There are often cases where .next
will either be a sibling, or a descendent, etc. 在许多情况下, .next
可能是同级或后代,等等。
Because .img:first
will always return the same element. 因为.img:first
将始终返回相同的元素。 Once an element is faded out you can move it to the end of the queue. 淡出元素后,您可以将其移到队列的末尾。
$('.next').click(function () {
$('.img:first').stop(true, true).fadeOut(function () {
$(this).next().fadeIn().end().appendTo(this.parentNode);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.