1

いくつかのプロトタイプコードをjQueryに変換しようとしています。

変換方法がわからない次の呼び出しがあります。

document.viewport.getHeight();
document.viewport.getScrollOffsets().top

質問

jQueryの上記のコードの同等性は何ですか?
ない場合、それを行うためのバニラの方法は何ですか?

4

2 に答える 2

2

最新のブラウザの場合:

document.documentElement.clientHeight
document.documentElement.scrollTop

jQueryの場合:

$(window).height();
$(window).scrollTop();
于 2013-03-14T16:48:25.520 に答える
2

jQueryの方法

窓の高さ

$(window).height();

上にスクロール

$(window).scrollTop();

バニラJavaScriptの方法:

窓の高さ

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;
}

スクロールオフセット:

var scrollY = window.pageYOffset;
于 2013-03-14T16:51:01.563 に答える