Search code examples
jqueryhovermouseoverjcarousel

How do i fire a click continuously while something is hovered?


Im pretty sure this has a simple solution. I am using jCarousellite, and i want to change the behaviour of built in nav buttons to fire on hover over.

$("#carousel").jCarouselLite({


 vertical: true,
 btnNext: ".btn-down",
 btnPrev: ".btn-up",
 visible:6,
 circular: false

});

$("#carousel .btn-down").hover(function() {

 $("#carousel .btn-down").click();

});

but it only fires once when mouseover, i need it to fire continueously while mouseover.


Solution

  • var nav = function() {
      $("#carousel .btn-down").click(); // next move
      $("#carousel").data(
        'hover', 
        window.setTimeout(nav, 1000); // continue in 1000 ms
      );
    };
    $("#carousel .btn-down").hover(
      nav,
      function() {
        window.cancelTimeout ($("#carousel").data('hover')); // stop the navigation
      }
    );