我有这个功能,当用户距离窗口底部 500 像素时触发点击。
一切正常,除非我在 css 中将 html 和 body 设置为 height:100%。
这是“工作”脚本。
$(document).ready(function() {
var timeout = '';
$(window).scroll(function (e) {
var intBottomMargin = 500;
clearTimeout(timeout);
//if less than intBottomMargin px from bottom
if ($(window).scrollTop() >= $(document).height() - $(window).height() - intBottomMargin) {
timeout = setTimeout(function(){
$("#next-paginav")[0].click();
}, 300);
}
});
});
当我的 html 和正文高度为 100% 时,如何使相同的脚本工作?
我相信这真的很简单。
最佳答案
我认为你的计算不正确:
if ($(window).scrollTop() >= $(document).height() - $(window).height() - intBottomMargin)
如果您的 body/html 是 100% 高度,则意味着您将其设置为视口(viewport)的高度。你以前有 float 元素吗?这可能就是您(之前的)高度计算有效的原因
试试这个:
if ($(window).scrollTop() >= $(document).height() - intBottomMargin)
关于jquery 问题与 html 高度 :100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15775393/