Jquery Slider Timer

谁都会走 提交于 2019-12-06 16:34:21

You can dynamically trigger click() on your a elements in a setInterval !

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() ;
});
  • Thanks to current++%slN the auto function will loop once the last button is triggered
  • The PAUSE thing detects events mouseenter 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
});

There is is a function setInterval

    function hi(){
        //Your code here
    }

    //set an interval
    setInterval(hi, 30000);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!