开发者

On scroll ,capture the last text in the screen?

I have a requirement wh开发者_如何学Goere i need to display 1000 images which will take lot of time if i need to display all at once . So each time the user scrolls , i want to know the last element or first element in the viewport .Is that possible using jquery ?How can i achieve it . Thanks in advance


Taken from this: Check if element is visible after scrolling

function isScrolledIntoView(elem)
{
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}

Now simply loop through your elements and test them each to see if they are visible and take the last one.

For a lot of elements this will be slow. I recommend doing some kind of sorting when the page loads and then doing a binary search instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜