[英]how to stop the element at footer line while moving it up and down with scroll
我添加了一个随着滚动向上和向下移动的元素,但是问题在于它与页脚合拢。 以下是我正在使用的示例代码
$(document).ready(function () {
var top = $('#comment').offset().top - parseFloat($('#comment').css('marginTop').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('#comment').addClass('fixed');
} else {
// otherwise remove it
$('#comment').removeClass('fixed');
}
});
});
样本HTML代码
<div id="commentWrapper">
<div id="comment">
<form>
<!-- take their response -->
</form>
</div>
</div>
我通过给出bottom:somevalue
及其现在可以正常工作来解决它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.