我已经构建了一个带有左右滚动的简单走马灯。现在我想每5秒自动滚动一次。以下是我的代码:
function carousel(){
$j('#carousel_ul li:first').before($j('#carousel_ul li:last'));
$j('#right_scroll img').click(function(){
var item_width = $j('#carousel_ul li').outerWidth() + 10;
var left_indent = parseInt($j('#carousel_ul').css('left')) - item_width;
$j('#carousel_ul:not(:animated)').animate({'left' : left_indent},800, 'easeOutExpo',function(){
$j('#carousel_ul li:last').after($j('#carousel_ul li:first'));
$j('#carousel_ul').css({'left' : '-750px'});
});
});
$j('#left_scroll img').click(function(){
var item_width = $j('#carousel_ul li').outerWidth() + 10;
var left_indent = parseInt($j('#carousel_ul').css('left')) + item_width;
$j('#carousel_ul:not(:animated)').animate({'left' : left_indent},800, 'easeOutExpo',function(){
$j('#carousel_ul li:first').before($j('#carousel_ul li:last'));
$j('#carousel_ul').css({'left' : '-750px'});
});
});
}
我该如何实现这个目标呢?提前感谢您的帮助。 :)
Mauro
setInterval
和setTimeout
!传递一个函数:setInterval(event, 5000);
和setInterval(function () {$j("#right_scroll img").click();}, 5000);
- Matt Ball