(function(){ var debug = false; var loadIframe = function(target){ if(debug)console.log('yt ll load %s', target.dataset.src); if(target.src != target.dataset.src)target.src = target.dataset.src; }; if(typeof IntersectionObserver === 'function' && document.querySelector){ var targets = document.querySelectorAll('.youtube-lazyload'); var observer = new IntersectionObserver(function(entries, curObs){ for(var entry in entries){ entry = entries[entry]; var isVisible = entry.intersectionRatio != 0; if(isVisible){ loadIframe(entry.target); //observer.unobserve(entry.target); } } }); for(var idx in targets) if(targets.hasOwnProperty(idx)) observer.observe(targets[idx], {threshold: [0.1]}); }else{ var entries = document.querySelectorAll('.youtube-lazyload'); for(var entry in entries) if(entries.hasOwnProperty(entry)) loadIframe(entries[entry]); } })();