R
R
Rodion Gashé2011-02-07 21:01:24
JavaScript
Rodion Gashé, 2011-02-07 21:01:24

JavaScript: event - the appearance of an element in the scope. How?

On Facebook, the news feed, when you scroll down the page, loads itself.
It's the same here: nebo-v-almazah.ru/earrings
Something got wrong and I can't figure out how to do it without constant checking through setInterval()
Maybe there is something like this in jQuery?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
H
homm, 2011-02-07
@zorba_buddha

var $win = $(window);
var $marker = $('#marker');
$win.scroll(function() {
    if ($win.scrollTop() + $win.height() >= $marker.offset().top) {
        $win.unbind('scroll');
        // load there
    }
});

O
Oleg Matrozov, 2011-02-07
@Mear

And the reaction to onScroll is not enough for you?

I
Ilya Alekseev, 2016-06-07
@ilyaalekseev

you can also do this so as not to add the height of the window -

var coords = $("#your_element").getBoundingClientRect();
var windowHeight = document.documentElement.clientHeight;

and then in check -
if (windowHeight >= coords.top)
{
...
}

U
Uno di Palermo, 2017-12-04
@rogerCopy

$(window).scroll(function() {
    var h = $(window).scrollTop();
    var yourElementHeight= $("#yourElement").offset().top; // координаты высоты верхнего края yourElement
    if (h > yourElementHeight) {
        //do...
    } 

//т.е. при высоте прокрутки > чем высота верхнего края yourElementHeight

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question