JavaScript: event — element appears in the viewport. How?

Facebook news feed, the page scroll down dotiruetsja itself.
Here is also the same: nebo-v-almazah.ru/earrings
I have to work late and I can't figure out how to do that without constant checking using setInterval()
Maybe there's something in jQuery?
October 10th 19 at 14:56
4 answers
October 10th 19 at 14:58
Solution
var $win = $(window);
var $marker = $('#marker');
$win.scroll(function() {
 if ($win.scrollTop() + $win.height() >= $marker.offset().top) {
$win.unbind('scroll');
 // load there
}
});
var $win = $(window), $marker = $('#marker');

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

setOnScroll();


after booting again setOnScroll(), if there's anything to ship.
Thank you! - shayna.Nitzsche76 commented on October 10th 19 at 15:01
October 10th 19 at 15:00
And the reaction on onScroll's not enough for you?
It always happens when you scalisi. I just thought maybe there's something there, like the appearance of the element in the scope. - shayna.Nitzsche76 commented on October 10th 19 at 15:03
I suspect that it is not simpler than described below homm - shayna.Nitzsche76 commented on October 10th 19 at 15:06
October 10th 19 at 15:02
still it is possible not to put the height of the window to do so
var coords = $("#your_element").getBoundingClientRect();
var windowHeight = document.documentElement.clientHeight;


and then, in the test -
if (windowHeight >= coords.top)
{
...
}
October 10th 19 at 15:04
$(window).scroll(function() {
 var h = $(window).scrollTop();
 var yourElementHeight= $("#yourElement").offset().top; // coordinates of top height yourElement
 if (h > yourElementHeight) {
//do...
 } 

//i.e. when the height of the scroll > the height of the upper edge yourElementHeight

Find more questions by tags JavaScript