How can I test it if it's greater than 100. For example how can I get an alert.
Here is my code that doesn't work, I don't know why.
var ScrollTop = $("body").scrollTop();
if (ScrollTop > 100){
alert("Scroll is greater than 100");
//document.getElementById('back-to-top').fadeOut;
}
To get or set the scroll position of an element, you follow these steps: First, select the element using the selecting methods such as querySelector() . Second, access the scroll position of the element via the scrollLeft and scrollTop properties.
The Element. scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content.
Use a scroll listener http://jsfiddle.net/6A6qy/
$(window).scroll(function(){...});
PERFECT FIDDLE EXAMPLE
var el = $('.test');
el.on('scroll', function(){
alert(el.scrollTop());
});
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