Javascript 解释jQuery的这种效果

Javascript 解释jQuery的这种效果,javascript,jquery,css,Javascript,Jquery,Css,请解释一下代码中发生了什么 <script type="text/javascript"> $(function () { var $scrollingDiv = $(".floatdetails"); $(window).scroll(function () { var y = $(window).scrollTop(), maxY = $('#foot').offset().top,

请解释一下代码中发生了什么

<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>

$(函数(){
变量$scrollingDiv=$(“.floatdetails”);
$(窗口)。滚动(函数(){
变量y=$(窗口).scrollTop(),
maxY=$(“#英尺”).offset().top,
scrollHeight=$scrollingDiv.height()
如果(y
我需要做的是不要让边距顶部小于0。你可以告诉我为什么我需要它。而且也不能让.floatdetails跨过页脚


很明显,你可以猜到我是jQuery的初学者。因此,任何帮助都将不胜感激。

请参阅评论中的解释

//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);
    }
});
//函数将在滚动时触发
$(窗口)。滚动(函数(){
//滚动高度的多少指定给y;
变量y=$(窗口).scrollTop(),
//$(“#英尺”)的顶部位置分配给maxY
maxY=$(“#英尺”).offset().top,
//为scrollHeight指定了$(“.floatdetails”)的高度
scrollHeight=$scrollingDiv.height()
如果(y
u$(窗口)的哪个部分不清楚。滚动(函数(){var y=$(窗口)。滚动顶部(),maxY=$('#foot')。偏移量()。顶部,我在回答中以注释的形式发布了解释。现在清楚了吗?