开发者

jquery prevent loop

开发者 https://www.devze.com 2023-03-17 08:29 出处:网络
i have a hover slide down panel which needs a delay when mouse leave. Like i have it now, hovering the trigger will result in multiple loops, so the panel goes crazy up & down.

i have a hover slide down panel which needs a delay when mouse leave. Like i have it now, hovering the trigger will result in multiple loops, so the panel goes crazy up & down. Here is the code:

 $(document).ready(function(){
(function(){
  var trigger = $('li.HotelPaneltrigger');
  var panel = trigger.find('.panel').hide();
    trigger.mouseenter(function(){panel.slideDown('slow');}).mouseleave开发者_如何转开发(function(){panel.slideUp('slow');});
 })();
});

I tried this without success: $(this).mouseleave(function () {

$(this).delay('500')panel.slideUp('slow');


I'm not exactly sure if I get you right, but I think invoking .stop() will do it for you.

panel.stop(true, true).slideDown('slow');

and

panel.stop(true, true).delay(500).slideUp('slow');

Reference: .stop()


Adding a .stop(true,true) before your slideDown and slideUp event should solve your problem, off the top of my head.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号