请问有人可以解释一下这段代码中发生了什么吗?
<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>
我需要做的是不要让margin-top小于0.您可以see here为什么我需要它。而且也不要让.floatdetails穿过页脚。
显然你可以猜到我是一个jQuery初学者。所以,任何帮助将不胜感激。
答案 0 :(得分: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);
}
});