Ye code jo aapne diya hai, lazy loading functionality ke liye hai jo images ko lazy load karta hai Intersection Observer ka istemal karke.
Jab aap ye code paste karenge, ye kuch functionalities provide karega:
Lazy Loading Images: Ye JavaScript code images ko lazy load karta hai. Jab browser viewport mein aati hai image, tab hi wo actual
srcattribute mein load hoti hai, isse initial page load time decrease hota hai.Alt Tag Generation: Image ka
altattribute generate kiya jata hai based on image ka filename. Isse accessibility ke liye better text generate hota hai jo visually impaired users ke liye helpful hota hai.Styling for a Follow Form: Ye CSS code ek form ke styling ke liye hai. Isse form ko specific tarike se style kiya gaya hai.
Form Container Styling: Form container ke liye CSS styling provide ki gayi hai jisse wo specific design aur layout follow kare.
Powered By Link: Powered by link styling ke liye di gayi hai.
Ye code snippet aapke web page ko visually enhance karne ke liye use kiya ja sakta hai aur images ko lazy load karke initial page load time ko reduce karne mein madad karega. Follow form ke liye bhi specific styling provide ki gayi hai.
👇paste this code just before the </body> tag
<script type="text/javascript">
function lazyLoadImages() {
var lazyImages = [].slice.call(document.querySelectorAll("img.lazy"));
if ("IntersectionObserver" in window) {
let lazyImageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
var lazyImage = entry.target;
lazyImage.src = lazyImage.dataset.src;
lazyImage.alt = lazyImage.src.split('/').pop().split('.')[0].replace(/-/g, ' ').replace(/\b\w/g, function(txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
lazyImage.classList.remove("lazy");
lazyImageObserver.unobserve(lazyImage);
}
});
});
lazyImages.forEach(function(lazyImage) {
lazyImageObserver.observe(lazyImage);
});
}
}
document.addEventListener("DOMContentLoaded", function() {
lazyLoadImages();
});
</script>
Comments
Post a Comment