我希望我的幻灯片标题(在Tumblr主题上)无限循环,而无需单击下一个箭头请帮助。下列代码
var interval = undefined;
$(document).ready(function() {
interval = setInterval(getNext, 3000);
$("a#next").on('click', getNext);
$("a#prev").on('click', getPrev);
});
function getNext() {
var $curr = $("#slides .slides:visible"),
$next = ($curr.next().length) ? $curr.next() : $("#slides .slides").first();
transition($curr, $next);
}
function getPrev() {
var $curr = $("#slides .slides:visible"),
$next = ($curr.prev().length) ? $curr.prev() : $("#slides .slides").last();
transition($curr, $next);
}
function transition($curr, $next) {
clearInterval(interval);
$next.css("z-index", 8).fadeIn("medium", function() {
$curr.fadeOut().css("z-index", 0);
$next.css("z-index", 7);
});
}
直接删除
clearInterval(interval);
中的transition()
函数。
JSFiddle