How To Find Scroll Top Value For Div
I am working on responsive site. We need when a user see video section that's need to autoplay. If set scroll top for video tag is not working. But i set scrolltop to window it's w
Solution 1:
You need use offest().top
to get distance to reach video
element. scrollTop
will get window scroll
distance not distance to an element. Just use this:
$('#test').offset().top
$(window).scroll(function () {
var scrollTop = $(window).scrollTop();
var scrollToVid = $('#test').offset().topconsole.log(scrollTop);
console.log(scrollToVid);
if ($(window).scrollTop() >= scrollToVid) {
alert('You reached to the video!');
}
});
Post a Comment for "How To Find Scroll Top Value For Div"