Reputation: 6482
I'm trying to convert some prototype code to jQuery.
I have these calls that I don't know the how to convert:
document.viewport.getHeight();
document.viewport.getScrollOffsets().top
What's the equality for the above code in jQuery?
If there is none, what is the vanilla way of doing it?
Upvotes: 1
Views: 713
Reputation: 3651
Window height:
$(window).height();
$(window).scrollTop();
Window height
var winHeight = 0;
if (document.body && document.body.offsetWidth) {
winHeight = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetHeight) {
winHeight = document.documentElement.offsetHeight;
}
if (window.innerHeight) {
winHeight = window.innerHeight;
}
Scroll offset:
var scrollY = window.pageYOffset;
Upvotes: 2
Reputation: 276436
In modern browsers:
document.documentElement.clientHeight
document.documentElement.scrollTop
In jQuery:
$(window).height();
$(window).scrollTop();
Upvotes: 2