2013-04-26 85 views
-1

請解釋一下這段代碼中發生了什麼?說明這個jQuery效果

<script type="text/javascript"> 
    $(function() { 
     var $scrollingDiv = $(".floatdetails"); 
     $(window).scroll(function() { 
      var y = $(window).scrollTop(), 
      maxY = $('#foot').offset().top, 
      scrollHeight = $scrollingDiv.height() 
      if (y < maxY - scrollHeight - 375) { 
       $scrollingDiv.stop().animate({ 
        "marginTop": ($(window).scrollTop()) + "px" 
       }, 2000); 
      } 
     }); 
    }); 
</script> 

我需要做的是不要讓邊距小於0,可以see here爲什麼我需要的。同時也不要讓浮游生物穿過頁腳。

顯然你可以猜測我是一個jQuery初學者。所以,任何幫助將不勝感激。

+0

解釋這sectin不清的ú? – 2013-04-26 09:33:16

+0

$(window).scroll(function(){ var y = $(window).scrollTop(), maxY = $('#foot')。offset()。top, – 2013-04-26 09:36:22

+0

我已經發布瞭解釋答案。現在清楚了嗎? – 2013-04-26 09:43:31

回答

0

查看評論

//Function will be triggered on scrolling 
$(window).scroll(function() { 
    //How much height is scrolled is assigned to y; 
    var y = $(window).scrollTop(), 
      //top position of the $('#foot') is assigned to maxY 
      maxY = $('#foot').offset().top, 
      //height of $(".floatdetails") is assigned to scrollHeight 
      scrollHeight = $scrollingDiv.height() 
    if (y < maxY - scrollHeight - 375) { 
     //Base od the condition $(".floatdetails") is animated 
     $scrollingDiv 
       .stop() 
       .animate({ 
      "marginTop": ($(window).scrollTop()) + "px" 
     }, 2000); 
    } 
});