왼쪽 및 오른쪽 스크롤로 간단한 회전식 컨베이어를 만들었습니다. 이제 5 초마다 자동으로 스크롤하고 싶습니다. 내 코드는 다음과 같습니다.jquery 동일한 이벤트를 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'});
});
});
}
어떻게 구현합니까? 사전에 감사합니다 :)
마우로
에서는 setTimeout 한 번만 할 것입니다. setInterval 함수를 계속해서 호출합니다 ... setInterval이이 상황에 더 좋습니다. – Gabriel
@gabriel - 맞아. Tks! – Topera
*'setInterval'과'setTimeout'에 문자열을 전달하지 마세요! 함수를 전달하십시오 :'setInterval (event, 5000); 그리고'setInterval (function() # right_scroll img ") click();}, 5000),' –