2013-07-01 3 views
1

Я пытаюсь предотвратить функцию mouseenter, пока пользователь прокручивает jQuery, но не может понять, какие-либо предложения?предотвращает функцию mouseenter при прокрутке

Код:

$(".li").mouseenter(function(){ 
$(this).children(".work_name").toggleClass("open", 400); 

$('.li').mouseleave(function(){ 
    $(this).children(".work_name").removeClass("open", 400); 
}); 

}); 

ответ

0

Вы могли бы реализовать это следующим образом:

window.isScrolling = false; 
$(window).scroll(function() { 
    window.isScrolling = true; 
    clearTimeout($.data(this, "scrollTimer")); 
    $.data(this, "scrollTimer", setTimeout(function() { 
     // If the window didn't scroll for 250ms 
     window.isScrolling = false; 
    }, 250)); 
}); 

Затем измените код так:

$(".li").mouseenter(function(){ 

// Prevent executing when the user is scrolling 
if (window.isScrolling) return; 

$(this).children(".work_name").toggleClass("open", 400); 

$('.li').mouseleave(function(){ 
    $(this).children(".work_name").removeClass("open", 400); 
}); 

}); 
+0

отлично работает, спасибо большое! – RoseCoder

 Смежные вопросы

  • Нет связанных вопросов^_^