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

后端 未结 4 699
长发绾君心
长发绾君心 2021-01-07 10:01

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.

$(\"#         


        
4条回答
  •  一向
    一向 (楼主)
    2021-01-07 10:49

    You can use setInterval to begin triggering the event at regular intervals on hover and use clearInterval to stop it when the user stops hovering. It'd also be cleaner to trigger the actual behavior you want instead of triggering a click event, assuming the plugin you're using supports such an API. Something like this:

    var effectInterval;
    
    $('#carousel .btn-down').hover(function() {
      effectInterval = setInterval(function() {
        $('#carousel').advanceToNextImage(); // sample API call, check your plugin's docs for how it might actually be done
      }, 5000);
    }, function() {
      clearInterval(effectInterval);
    });
    

提交回复
热议问题