在没有jQuery的情况下找到滚动条的垂直位置 [英] Find the vertical position of scrollbar without jQuery
本文介绍了在没有jQuery的情况下找到滚动条的垂直位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找到滚动条的垂直位置,类似于jQuery的scrollTop(),但没有jQuery。还有其他选择吗?
I'm trying to find the vertical position of the scrollbar a function similar to jQuery's scrollTop() but with no jQuery. Are there any alternatives?
推荐答案
跨浏览器解决方案:
var supportPageOffset = window.pageXOffset !== undefined;
var isCSS1Compat = ((document.compatMode || "") === "CSS1Compat");
var scrollLeft = supportPageOffset ? window.pageXOffset : isCSS1Compat ? document.documentElement.scrollLeft : document.body.scrollLeft;
var scrollTop = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop;
这篇关于在没有jQuery的情况下找到滚动条的垂直位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文