Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PrototypeJS到jQuery | document.viewport_Javascript_Jquery_Prototypejs - Fatal编程技术网

Javascript PrototypeJS到jQuery | document.viewport

Javascript PrototypeJS到jQuery | document.viewport,javascript,jquery,prototypejs,Javascript,Jquery,Prototypejs,我正在尝试将一些原型代码转换为jQuery 我不知道如何转换这些呼叫: document.viewport.getHeight(); document.viewport.getScrollOffsets().top 问题 上述代码在jQuery中的相等性是什么? 如果没有,一般的做法是什么?在现代浏览器中: document.documentElement.clientHeight document.documentElement.scrollTop 在jQuery中: $(window).

我正在尝试将一些原型代码转换为jQuery

我不知道如何转换这些呼叫:

document.viewport.getHeight();
document.viewport.getScrollOffsets().top
问题 上述代码在jQuery中的相等性是什么? 如果没有,一般的做法是什么?

在现代浏览器中:

document.documentElement.clientHeight
document.documentElement.scrollTop
在jQuery中:

$(window).height();
$(window).scrollTop();
在现代浏览器中:

document.documentElement.clientHeight
document.documentElement.scrollTop
在jQuery中:

$(window).height();
$(window).scrollTop();
jQuery方式 窗口:

:

方式: 窗高

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;
jQuery方式 窗口:

:

方式: 窗高

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;

document.viewport.getScrollOffsets.top如何?没有jQuery方法?@ErikLandvall如果您感兴趣,我也添加了一种普通的javascript方法。@RobinBanbaalen为什么建议document.body.offsetHeight而不是document.documentElement.scrollTop?对我来说,这似乎是一个更糟糕的解决方案。@BenjaminGruenbaum document.body.offseight是用来获取窗口高度,而不是滚动位置;检索对象相对于布局或坐标父对象的高度,如offsetParent属性所指定。document.viewport.getScrollOffsets.top如何?没有jQuery方法?如果您感兴趣,请@ErikLandvall,我还添加了一种普通的javascript方式。@Robinbanbaalen为什么建议document.body.offsetHeight而不是document.documentElement.scrollTop?对我来说,这似乎是一个更糟糕的解决方案。@BenjaminGruenbaum document.body.offseight是用来获取窗口高度,而不是滚动位置;按照offsetParent属性的指定,检索对象相对于布局或坐标父对象的高度。