SHARE
TWEET

Untitled

a guest Mar 26th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <video autoplay muted loop playsinline width="610" height="254" poster="one-does-not-simply.jpg">
  2.   <source data-src="one-does-not-simply.webm" type="video/webm">
  3.   <source data-src="one-does-not-simply.mp4" type="video/mp4">
  4. </video>
  5.  
  6. document.addEventListener("DOMContentLoaded", function() {
  7.   var lazyVideos = [].slice.call(document.querySelectorAll("video.lazy"));
  8.  
  9.   if ("IntersectionObserver" in window) {
  10.     var lazyVideoObserver = new IntersectionObserver(function(entries, observer) {
  11.       entries.forEach(function(video) {
  12.         if (video.isIntersecting) {
  13.           for (var source in video.target.children) {
  14.             var videoSource = video.target.children[source];
  15.             if (typeof videoSource.tagName === "string" && videoSource.tagName === "SOURCE") {
  16.               videoSource.src = videoSource.dataset.src;
  17.             }
  18.           }
  19.  
  20.           video.target.load();
  21.           video.target.classList.remove("lazy");
  22.           lazyVideoObserver.unobserve(video.target);
  23.         }
  24.       });
  25.     });
  26.  
  27.     lazyVideos.forEach(function(lazyVideo) {
  28.       lazyVideoObserver.observe(lazyVideo);
  29.     });
  30.   }
  31. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top