更新时间:2023-11-17 16:57:58
您可以在 setInterval
a 元素上动态触发 click()
代码>!
var intv;
var current = 0; // STARTING SLIDE(<li>element button) INDEX
var slN = $('#slider li').length; // get number of slides(buttons.. all the same)
// your function here with
// clearInterval(intv);
// in the second line.
// In third line put:
// current = $(this).closest('li').index();
// AUTO SLIDE
function auto(){
intv = setInterval(function() {
$('#slider ul li').eq( current++%slN ).find('a').click();
}, 5000 );
}
auto(); // to start immediately auto-slide
// PAUSE ON MOUSEOVER
$('#slider').on('mouseenter mouseleave', function( e ){
var onMouEnt = e.type=='mouseenter' ? clearInterval(intv) : auto() ;
});
current++%slN
,一旦最后一个按钮被触发,auto
函数就会循环mouseenter
和 mouseleave
并使用三元运算符来执行:
current++%slN
the auto
function will loop once the last button is triggeredmouseenter
and mouseleave
over your gallery and uses a ternary operator to do:$('#slider').on('mouseenter mouseleave', function( e ){ // catch eVENT
var onMouEnt = e.type=='mouseenter' ? // if e IS mouseenter
clearInterval(intv) : // clear autoslide interval
auto() ; // else (is mouseleave) run 'auto' fn
});