Skip to content

Instantly share code, notes, and snippets.

@norfish
Last active May 19, 2017 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norfish/f762409caa2690bf6542f0cb1a42e625 to your computer and use it in GitHub Desktop.
Save norfish/f762409caa2690bf6542f0cb1a42e625 to your computer and use it in GitHub Desktop.
判断元素在是否在可视区域 check element in viewport(include part of)
// 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