2018년 12월 2일

오늘 한 일:

lazy loading - 2

1. getBoundingClientRect 사용하기

intersectionObserver api의 호환성 문제때문에(ie 미지원) getBoundingClientRect를 사용할 수 있음

getBoundingClientRect()로 간단하게 visibility 체크

function isInViewport(el) {
    domRect = el.getBoundingClientRect();
    return (
        domRect.bottom >= 0 &&
        domRect.right >= 0 &&
        domRect.top <= (windon.innerHeight || document.documentElemnt.clientHeight) &&
 		domRect.left <= (windon.innerWidth || document.documentElemnt.clientWidth) &&       
    )
}

2. noscript

이미지로 이동할 수 있는 링크를 먼저 생성

이미지 로드가 되면 링크 삭제 후 로드된 이미지 보이기