我正在寻找一个非常基本的轮播功能与jQuery。
它应该:
在两个图像之间无限滚动每两三秒左右滚动一次没有导航/按钮/文本
如下所示:http://jsfiddle.net/UWbrQ/172/
(function() {
var first = $('.item').first(),
last = $('.item').last(),
itemWidth = first.width(),
carousel = $('.carousel');
carousel.prepend(last.clone()).append(first.clone());
carousel.width(itemWidth * $('.item').length);
carousel.css({left: -itemWidth});
$('.prev').on('click', function(e){
e.preventDefault();
carousel.animate({left: '+=' + itemWidth}, 300, function(){
if(Math.abs(carousel.position().left) < 2) {
carousel.css({left: -itemWidth * (carousel.children().length - 2)});
}
});
return false;
});
$('.next').on('click', function(e){
e.preventDefault();
carousel.animate({left: '-=' + itemWidth}, 300, function(){
if(Math.abs(carousel.position().left + itemWidth * (carousel.children().length - 1)) < 2) {
carousel.css({left: -itemWidth});
}
});
return false;
});
})();但具有自动功能,并且不需要上一步/下一步按钮。
编辑:在这里找到一个好的:http://jsfiddle.net/IrvinDominin/2Kspn/ EDIT2: Nvm,知道了:http://jsfiddle.net/IrvinDominin/2Kspn/1/
但是它在最后一张幻灯片上停止了..TYIA
发布于 2014-03-20 21:29:10
需要使用jQuery的setTimeout函数,每隔2/3秒调用(触发点击)一次next。
setTimeout(function() {
// Do something after 2 seconds
}, 2000);https://stackoverflow.com/questions/22534281
复制相似问题