Last active
March 6, 2018 07:35
-
-
Save nicholasxjy/f711cb68d60f68a85e50245384698dd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 屏幕可视窗口大小 | |
window.innerHeight // 标准浏览器及IE9+ | |
document.documentElement.clientHeight // 标准浏览器及低版本IE标准模式 | |
document.body.clientHeight // 低版本混杂模式 | |
// 浏览器窗口顶部与文档顶部之间的距离,也就是滚动条滚动的距离 | |
window.pagYOffset // 标准浏览器及IE9+ | |
document.documentElement.scrollTop // 兼容ie低版本的标准模式 | |
document.body.scrollTop // 兼容混杂模式 | |
//get scroll top | |
var getScrollTop = function (element) { | |
if (element === window) { | |
return Math.max(window.pageYOffset || 0, document.documentElement.scrollTop); | |
} | |
return element.scrollTop; | |
}; | |
var getElementTop = function (element) { | |
if (element === window) { | |
return getScrollTop(window); | |
} | |
return element.getBoundingClientRect().top + getScrollTop(window); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment