【发布时间】:2012-02-02 04:43:48
【问题描述】:
jsFiddle 在这里:http://jsfiddle.net/qBQD4/
真的很简单;我想要右箭头向前移动图像,左箭头在简单的幻灯片中向后移动它们。我在将要实现此代码的页面上运行了多个幻灯片,因此我选择了 .next() 路由,而不仅仅是指定唯一的 div id。 HTML 是:
<div class="media">
<div class="slideButtons">
<span class="prev"><</span>
<span class="next">/ ></span>
</div>
<ul class="gallery" id="olympGallery">
<li><img src="http://i.imgur.com/8aA7W.jpg" alt="" title="" /></li>
<li><img src="http://i.imgur.com/jE7vj.jpg" alt="" title="" /></li>
<li><img src="http://i.imgur.com/L7lVg.jpg" alt="" /></li>
</ul>
</div>
jQuery 代码是:
var speed = 100;
$(".prev").click(function() {
var now = $(this).next("ul.gallery").children(":visible"),
last = $(this).next("ul.gallery").children(":last"),
prev = now.prev();
prev = prev.index() == -1 ? last : prev;
now.fadeOut(speed, function() {prev.fadeIn(speed);});
});
$(".next").click(function() {
var now = $(this).next("ul.gallery").children(':visible'),
first = $(this).next("ul.gallery").children(':first'),
next = now.next();
next = next.index() == -1 ? first : next;
now.fadeOut(speed, function() {next.fadeIn(speed);});
});
$(".gallery li").click(function() {
var first = $(this).parent().children(':first'),
next = $(this).next();
next = next.index() == -1 ? first : next;
$(this).fadeOut(speed, function() {next.fadeIn(speed);});
});
最后,一点 CSS:
.prev, .next {position: relative; padding: 3px; font-size:50px; font-weight: 900; cursor:pointer;
}
.gallery li{display:none; list-style:none;}
.gallery li:first-child {display:block;}
.gallery img {
max-height:550px
}
第三个功能工作正常(单击图像进入系列中的下一个)。但是,前两个完全被打破了。我在这里做错了什么?
【问题讨论】: