Search
 
SCRIPT & CODE EXAMPLE
 

HTML

html lazy loading images

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

how to add lazy loading in html

lazy loading in html

<img src="myimage.jpg" loading="lazy" alt="..." />
<iframe src="content.html" loading="lazy"></iframe>
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

how to add lazy loading in html

<img src="path-to-image.png" loading="lazy" alt="something"/>
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 :: bold in bootstrap 
Html :: img tamanho html 
Html :: js on page finished loading 
Html :: syntax for ngfor 
Html :: include favicon into website 
Html :: elementor text control 
Html :: set textbox into center of div in bootstrap 
Html :: html form select 
Html :: html form only accept zip folders 
Html :: como cambiar el color html 
Html :: html template 
Html :: import image in html 
Html :: target blank html 
Html :: radio buttons html 
Html :: vue router link dynamic id 
Html :: jsf axonivy sub component 
Html :: spinup wp increate max upload size 
Html :: md cheat sheet 
Html :: bootstrap radio 
Html :: accept method jsf component 
Html :: how to redirect to gmail with a tag html 
Html :: bootstrap diable backround on modal 
Html :: iframe maps 
Html :: input type phone number 
Html :: how to add ads on html 
Html :: robots txt disallow all 
Html :: reactive forms radio button 
Html :: pyscript python 
Html :: applying padding increases the size of the element 
Html :: call modal by id href 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =