Reputation: 3737
Is there a way of identifying visible order of two elements using js of jquery?
for example: there is a element with position:fixed
when scrolling the window i need to identify if it is in below the footer div
or above the footer div
some times it look likes this
element One
footer div
but after scrolling it look likes this
footer div
element one
I want to identify those two situations separately.
Upvotes: 0
Views: 49
Reputation: 68393
You can compare element.offsetTop of both the elements
For example
var e1 = document.getElementById("elementOne");
var e2 = document.getElementById("footerDiv");
if ( e1.offsetTop > e2.offsetTop )
{
//your logic
}
jquery equivalent would be offset() method
var e1 = $( "#elementOne" );
var e2 = $( "#footerDiv" );
if ( e1.offset().top > e2.offset().top )
{
//your logic
}
Upvotes: 3