jquery 问题与 html 高度 :100%

标签 jquery css

我有这个功能,当用户距离窗口底部 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/

相关文章:

javascript - FineUploader错误处理

html - 如何在有序列表中隐藏元素符号编号后的点?

javascript - 引入 "offcanvas"滑入式菜单的 jQuery 函数不起作用

php - jquery Ajax 成功后突出显示数据

javascript - 加载一组照片时,如何为每个 imageID 制作唯一的评论按钮功能?

html - 在悬停另一个元素时更改元素的属性

html - 使工具提示位置固定

jquery - 选择另一个单选按钮时将单选重置为未选中状态

css - Angular 半径不起作用?

css - 文本框是垂直居中对齐之类的……顶部或文本顶部不起作用