I'm asking this because I'm trying to get the distance between the viewport top and a scrollable element top, then when it meets a specific value, I will use it in an If statement.
example:
if (viewport.top > div.top) {
div.style.background = "blue";
} else {
div.style.background = "red";
}
- if this was possible, does that value go negative when the element is out of viewport?
- is the viewport top always = 0 ?
please help me understand this.
thank you.