jQuery queues fadeIn() on scroll

My fadeIn on scroll seems to be triggering every time I scroll which is what I want. But this queues up the animation and ends up running well after the user has stopped scrolling.

I have tried using the .stop(true, true) function but I believe this does not work on a if or else statement.

My code so far:

if($('.icon').isOnScreen()){
    $('.icon').fadeIn("slow");  
} else {
    $('.icon').fadeOut("slow"); 
};

I have tried below but this does not work

if($('.icon').isOnScreen()){
    $('.icon').stop(true,true).fadeIn("slow");  
} else {
    $('.icon').stop(true,true).fadeOut("slow"); 
};

你有没有试过他的?

var isfadeId;
if($('.icon').isOnScreen()){
   if(!isfadeId) $('.icon').fadeIn("slow");
   isfadeId = true;
} else {
   if(isfadeId) $('.icon').fadeOut("slow"); 
   isfadeId = false;
};

解决它,谢谢大家

if($('.box').isOnScreen()){
    if($('.icon').isOnScreen()){
        $('.icon').fadeIn("slow");      
    } else {
        $('.icon').fadeOut("slow"); 
    }
} else {
    $('.icon').stop().fadeOut("slow");  
};
链接地址: http://www.djcxy.com/p/83608.html

上一篇: 如何正确评估从Behat到Selenium的JavaScript代码?

下一篇: jQuery队列fadeIn()滚动