Last active
May 19, 2017 08:59
-
-
Save norfish/f762409caa2690bf6542f0cb1a42e625 to your computer and use it in GitHub Desktop.
判断元素在是否在可视区域 check element in viewport(include part of)
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
// include part of the element | |
// 包含元素的一部分区域在可以区域 | |
function isElementVisble(el) { | |
if(!el) { | |
return; | |
} | |
var viewportHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); | |
var elPos = el.getBoundingClientRect(); | |
return ( elPos.top > 0 && (elPos.top < viewportHeight) ) || | |
(elPos.bottom > 0 && elPos.bottom < viewportHeight); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment