Search
 
SCRIPT & CODE EXAMPLE
 

HTML

html lazy loading images

<img loading="lazy" src="https://via.placeholder.com/320x200" alt="Lazy loaded image" />
Comment

html lazy load images

<img src="image.png" loading="lazy" alt="…" style="height:200px; width:200px;">
Comment

lazy load image

<img src="image.png" loading="lazy" alt="…" width="200" height="200">
Comment

Lazy loading images

const imgTargets = document.querySelectorAll("img[data-src]");

const imgObserve = function (entries, observer) {
  const [entry] = entries;
  console.log(entry);

  //replace src with data-src
  if (!entry.isIntersecting) {
    return;
  }
  entry.target.src = entry.target.dataset.src;

  //load event
  entry.target.addEventListener("load", function () {
    entry.target.classList.remove("lazy-img");
  });

  observer.unobserve(entry.target);
};

const imgOptions = {
  root: null,
  threshold: 0,
  rootMargin: "200px",
};

const imgObserver = new IntersectionObserver(imgObserve, imgOptions);

imgTargets.forEach(function (img) {
  imgObserver.observe(img);
});
Comment

PREVIOUS NEXT
Code Example
Html :: trash icon html 
Html :: registration form template bootstrap 
Html :: svg as button 
Html :: html css text style on a word 
Html :: html to powerpoint 
Html :: flutter web load html 
Html :: block level elements 
Html :: how to put your email in html 
Html :: how to add css file in wordpress 
Html :: favicon.ico html 
Html :: ng-src 
Html :: Server side validations Laravel 
Html :: tutorialspoint html 
Html :: html table basics 
Html :: cahnge bootstrap navbar color 
Html :: img srcset 
Html :: css image slideshow 
Html :: picsum 
Html :: favicon x shortcut icon 
Html :: markdown background colour 
Html :: bootstrap nav nav tabs float right 
Html :: import ionicons 
Html :: how to make html element center of the screen 
Html :: tailwind rounded top left 
Html :: how to install font-aweseome usin npm 
Html :: name input html 
Html :: how to add bg html 
Html :: ignor < in html 
Html :: css how to place an icon on a photo 
Html :: how to make email required in html 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =