我想在浏览器滚动条上加载到50%的少量数据

对于使用jquery我写了以下函数:

$(window).on('scroll', function () {
            alert("scrolling");
            if ($(window).scrollTop() + $(window).innerHeight() >= $(window)[0].scrollHeight * 0.5) {

                if (counter < modules.length) {
                    LoadData(modules[counter]);
                }
                counter += 1;
            }
        })


但它不起作用,我该如何解决?

我尝试过的是:

$(window).scroll(function () {
            if ($(window).scrollTop() == $(document).height() - $(window).height()) {
                alert("you are at bottom");
            }
        });


但我不希望警报在底部触发,仅为50%

最佳答案

要检测滚动是否已达到页面的50%,请使用:

if ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.5){


剩下的我们应该知道LoadData(modules[counter]);里面有什么

http://jsfiddle.net/carlodurso/a5wmLzfm/

关于javascript - $(window).on('scroll',function()当滚动到50%时,我要加载少量数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26894516/

10-09 17:29