element in viewport or not 3f

Solutions on MaxInterview for element in viewport or not 3f by the best coders in the world

showing results for - "element in viewport or not 3f"
Rafael
21 Aug 2017
1function isElementInViewport (el) {
2
3    // Special bonus for those using jQuery
4    if (typeof jQuery === "function" && el instanceof jQuery) {
5        el = el[0];
6    }
7
8    var rect = el.getBoundingClientRect();
9
10    return (
11        rect.top >= 0 &&
12        rect.left >= 0 &&
13        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /* or $(window).height() */
14        rect.right <= (window.innerWidth || document.documentElement.clientWidth) /* or $(window).width() */
15    );
16}
17