댓글 검색 목록

[javascript] 요소가 뷰포트에 있는지 확인 (9/86)

페이지 정보

작성자 운영자 작성일 20-03-31 12:42 조회 884 댓글 0

ele 요소가 뷰포트에 표시되면 다음 함수는 true를 반환합니다.


https://htmldom.dev/check-if-an-element-is-in-the-viewport 


const isInViewport = function(ele) {
    const rect = ele.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
};



댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.