Using jquery, how can you set an event that triggers when there is a vertical scroll visible, and when you change from top half of page to bottom half of page, and vice versa.
So for example, if the vertical scroll bar is there, and then I am looking somewhere on the page which is in the top half of the page, and then move down so I am in the bottom half of the page, the function happens. Then if I move back up so I am in the top half again, the function happens.
Thanks.
var midHeight = jQuery(window).height() / 2 //Splits screen in half
$(window).scroll(function () {
if ($(window).scrollTop() > midHeight) {
//Do something on bottom
} else {
//Do something on top
}
})
well jQuery does have these methods you can use on an element:
.scrollTop() - get top scroll position on an element in the viewport
.scrollLeft() - get left scroll position on an element in the viewport
Also there is the scroll event - that triggers when a viewport/element scrolls within another one (or the window):
.scroll()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With