English 中文(简体)
less无止境的喂养方法
原标题:Alternatives to jQuery endless scrolling

是否有别的办法来替代 j的无休止的roll生?

http://www.beyondcoding.com/2009/01/15/release-jquery-plugin-endless-scroll/

最佳回答
问题回答

这应当做到同样的trick,而没有花钱。

$(window).scroll(function () { 
   if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
      //Add something at the end of the page
   }
});

EDIT Jan 15, 2014

@pere s comment, it s better to use the code below to prevent over amount of eventfire.

Inspired from this answer https://stackoverflow.com/a/13298018/153723

var scrollListener = function () {
    $(window).one("scroll", function () { //unbinds itself every time it fires
        if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
            //Add something at the end of the page
        }
        setTimeout(scrollListener, 200); //rebinds itself after 200ms
    });
};
$(document).ready(function () {
    scrollListener();
});

结合Ergec的答复和Pere的评论:

function watchScrollPosition(callback, distance, interval) {
    var $window = $(window),
        $document = $(document);

    var checkScrollPosition = function() {
        var top = $document.height() - $window.height() - distance;

        if ($window.scrollTop() >= top) {
            callback();
        }
    };

    setInterval(checkScrollPosition, interval);
}

<代码>distance 是从屏幕底部发射的素数。

<代码>interval是检查频率(每秒250-1,000次是合理的)。

我找不到我完全想要的东西,我从头开始就建了一座。 它具有暂停作用的特点,因此它不会随着你的发展而无休止地装载。 有时有人可能想看到页脚。 它只是指一个“更多”纽芬兰语继续使用。 我也把当地人包括在内。 如果用户点击,他们就会失去结果的位置。

http://www.hawkee.com/snippet/9445/

它还具有可被要求操纵新附结果的反馈功能。

这应当考虑到用户在事件发生前到达网页底部的ug。 我在我的项目中看到这一点,如果你已经把此事重新放在网页的底部,那么你在开始活动之前就应当加以检查。

var scrollListener = function () {
    executeScrollIfinBounds();
    $(window).one("scroll", function () { //unbinds itself every time it fires
       executeScrollIfinBounds();
        setTimeout(scrollListener, 200); //rebinds itself after 200ms
    });
};
$(document).ready(function () {
    scrollListener();
});

function executeScrollIfinBounds()
{
     if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
            //Add something at the end of the page
        }
}




相关问题
how to detect Android ListView Scrolling stopped?

I m trying to do something after scrolling stopped.So, I tried using OnScrollListener#onScrollStateChanged(SCROLL_STATE_IDLE) to detect when the scrolling stopped(either TOUCH_SCROLL or FLING)(at 1.5 ...

jQuery - ScrollTo and Serial Scroll not working together

I have tested the scrollTo() plugin, but I need a way to stop the scrolling animation, so I am looking at serialScroll(). Here is what I used with scrollTo: $( #scroller ).scrollTo( 1000px , 3000); ...

Scrolling to the bottom of a div

As part of an ajax chat room (using prototype framework) I am working on I scroll the user to the bottom each time a message is added using the below js. However if the user has scrolled up and the ...

Displaying news with javascript

I keep coming up against this issue. Displaying news on a website. And I d like to come up with a solution to use like a template, something I can just drop on a site easily. The solution I keep ...

UITextview content moves up when textview is selected

I am pretty new to this iPhone dev thing but so far I have built a pretty good app but I have stumbled into this problem that for the life of me I cannot seem to solve. Basically the app is a chat ...

热门标签