Reputation: 2555
I am wondering if there is a way to tell if the page has scrolled over a certain div. I am trying to change the color of a div when it has past a certain point on the page. I know I can use the scrolltotop method to do the job:
if($(window).scrollTop() > 0){
//code
}
Although I am wondering if I would have to get the divs height on the page and then go from there or is there a built in method to check if a div has been scrolled to?
Upvotes: 0
Views: 43
Reputation: 82231
What you can do is take the sum of the scrollTop and innerHeight and when it equals to the scrollHeight, you've reached the end of the div.something like this:
$('divselector').bind('scroll', function() {
if($(this).scrollTop() + $(this).innerHeight()>=$(this)[0].scrollHeight)
{
alert('End of div');
}
})
Upvotes: 2
Reputation: 9947
May be like this
Get the scroll height of div in variable divHeight
check if current Window.ScrollTop > divHeight
is greater than this variable
apply the chnage
Upvotes: 1