我正在使用本教程http://jqueryfordesigners.com/fixed-floating-elements/使我的div在用户滚动时随页面移动。它的作用就像一个魅力,但直到你到达我的网页底部,div仍然是固定的位置,并仍然从他的父母div到footer。 的JavaScript:停止在页脚前移动div页面
$(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');
}
});
});
CSS:
#comment.fixed {
position: fixed;
top: 0;
}
这里是我的网页,所以你可以看看究竟是我的问题: http://testportal.jon.cz/projekt-konfigurator/konfig.html
对不起,我的英语,并感谢您的答案: )
你可以发布一些代码?不知道如何修复一些东西,却没有看到它是如何构建的 – Adjit 2014-10-28 14:09:58
没有代码,没有收获... – Shaeldon 2014-10-28 14:10:06
整个代码我用它是在第一个链接 – 2014-10-28 14:12:37