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

0 like 0 dislike
4 views
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?
by | 4 views

4 Answers

0 like 0 dislike
var $win = $(window); var $marker = $('#marker'); $win.scroll(function() { if ($win.scrollTop() + $win.height() >= $marker.offset().top) { $win.unbind('scroll'); // load there } }); 
by
0 like 0 dislike
And the reaction on onScroll's not enough for you?
by
0 like 0 dislike
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) { ... }
by
0 like 0 dislike
$(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
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
5 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Jun 3, 2019 by Tolly
110,608 questions
257,186 answers
0 comments
28,757 users