I was wondering if there is a way of finding out whether a browser window has a scrollbar visible, in JQuery?
Here's the code I'm working with:
var hContent = $("body").height();
var hWindow = $(window).height();
if(hContent>hWindow) {
$('#scroll-top').fadeIn(250);
}
else {
$('#scroll-top').fadeOut(250);
}
Any help is Greatly Appreciated, Thanks
Use the following function.
function checkScrollBar() {
var hContent = $("body").height(); // get the height of your content
var hWindow = $(window).height(); // get the height of the visitor's browser window
// if the height of your content is bigger than the height of the
// browser window, we have a scroll bar
if(hContent>hWindow) {
return true;
}
return false;
}
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