我已经找到了解决方案,但我是JQuery的新手。使用下一个和上一个按钮浏览多个div
如何更改它,以便我可以一次显示三个div,并且单击下一个或上一个按钮时,它将前进1而不是一次仅显示一个。
这里是JS小提琴我看:
http://jsfiddle.net/TrueBlueAussie/aVJBY/468/
,这是JQuery的:
function updateItems(delta)
{
var $items = $('#group').children();
var $current = $items.filter('.current');
$current = $current.length ? $current : $items.first();
var index = $current.index() + delta;
// Range check the new index
index = (index < 0) ? 0 : ((index > $items.length) ? $items.length : index);
$current.removeClass('current');
$current = $items.eq(index).addClass('current');
// Hide/show the next/prev
$("#prev").toggle(!$current.is($items.first()));
$("#next").toggle(!$current.is($items.last()));
}
$("#next").click(function() {
updateItems(1);
});
$("#prev").click(function() {
updateItems(-1);
});
// Cause initial selection
updateItems(0);
哪里的JavaScript公爵在隐瞒什么?当然,有少于10行代码的解决方案! – Raoulito
我编辑了小提琴:http://jsfiddle.net/aVJBY/552/ 这样你总是至少有第一个或最后一个div可见,他们不能全部隐藏。 – Raoulito