簡體   English   中英

為什么$(window).height()和$(document).height()等效項在Firefox中無法正常工作?

[英]Why doesn't $(window).height() and $(document).height() equivalency work well in Firefox?

我正在使用Tumblr的API來制作我發布到Tumblr的照片的提要。 我的想法是具有無限滾動功能,可加載20張圖像。

最初的20張圖像加載良好。 這是我的代碼,用於加載后續的圖像集:

var o = 0;

$(window).scroll(function () {
    if ($(window).scrollTop() + 1 >= $(document).height() - $(window).height()) {
        o += 20;
        $.ajax({
            url: 'http://api.tumblr.com/v2/blog/howwesabah.tumblr.com/posts?api_key=PtoHvq51kOdQlzU6YclOfGOlTuwfm5Chf1cScFnFNhbHxWMDWH&offset=' + o,
            dataType: 'jsonp',
            success: function (results) {
                console.log(results);

                for (j = 0; j <= 19; j++) {
                    var photourl = results.response.posts[j].photos[0].alt_sizes[3].url;
                    var photolink = results.response.posts[j].short_url;
                    $('#tumblr #container').append('<div class="item"><img src="' + photourl + '"/></div>');
                }

            }
        });
    }
});

在Chrome / Safari / Opera甚至IE中,這一切都沒有問題。 但是,當我滾動到文檔底部時,Firefox似乎只是不想加載圖像。 我已經在這里讀到了 Firefox和其他瀏覽器之間有時存在1px的差異,但是這似乎並不能解決問題。

我知道這是一個特定的問題,因此與Stackoverflow規范背道而馳,所以我想我的一般問題(請牢記我自己的問題)是Firefox發生了什么以及$(window).height()和$(document )。高度()?

$(window).height(); 將返回可見窗口的高度。

$(document).height(); 將返回整個文檔的高度,而不僅僅是可見部分。

工作實例

就是說,我認為您的特定問題不在於if語句...
我對其進行了測試,它在Firefox,Chrome和IE9中似乎同樣有效。

工作示例2

$(window).scroll(function () {
    if ($(window).scrollTop() +1 >= $(document).height() - $(window).height()) {
        $('body').css('background','red');
    }else{
        $('body').css('background','none');
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM