superhero
superhero

Reputation: 6482

PrototypeJS to jQuery | document.viewport

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

Question

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

Answers (2)

Robin van Baalen
Robin van Baalen

Reputation: 3651

jQuery way

Window height:

$(window).height();

Scroll top:

$(window).scrollTop();

Vanilla javascript way:

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

Benjamin Gruenbaum
Benjamin Gruenbaum

Reputation: 276436

In modern browsers:

document.documentElement.clientHeight
document.documentElement.scrollTop

In jQuery:

$(window).height();
$(window).scrollTop();

Upvotes: 2

Related Questions