2012-05-18 146 views
1

滾動100px後,我的div很好地淡出,但不會在300px滾動後淡入。如何淡出,在窗口滾動中淡入div?

任何想法?

$(document).ready(function(){ 
    $(window).scroll(function() { 
     if ($(this).scrollTop() > 100) { 
      $('#menuWrap').animate({opacity: 0.5}, 1000);    
      }  
     if ($(this).scrollTop() > 300) { 
      $('#menuWrap').animate({opacity: 1}, 1000); 
      } 
    }); 
}); 

回答

1

嘗試添加stop()stop(true,true) befaore animate(..)

$(document).ready(function(){ 
    $(window).scroll(function() { 
     if ($(this).scrollTop() > 100) { 
      $('#menuWrap').stop().animate({opacity: 0.5}, 1000); 
      } 
     if ($(this).scrollTop() > 300) { 
      $('#menuWrap').stop().animate({opacity: 1}, 1000); 
      } 
    }); 
}); 
+0

這工作就像一個魅力!謝謝。 –

+1

@ReesWharton任何時候,你能接受它作爲答案 – mgraph

+0

爲什麼.stop()使這項工作? –