2013-04-26 68 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); 
    } 
});