LazyLoad.js Example

Developer
Size
2,537 Kb
Views
26,312

How do I make an lazyload.js example?

Demo of a small JavaScript thingy I made to lazy load content.. What is a lazyload.js example? How do you make a lazyload.js example? This script and codes were developed by Kevin Gimbel on 08 September 2022, Thursday.

LazyLoad.js Example Previews

LazyLoad.js Example - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>lazyLoad.js Example</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Scroll down</h1>
<div class="playlist">
<iframe width="100%" height="450" scrolling="no" frameborder="no" src="" data-src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/186211537&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
<iframe width="100%" height="450" scrolling="no" frameborder="no" src="" data-src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/116098730&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>
</div> <script src="js/index.js"></script>
</body>
</html>

LazyLoad.js Example - Script Codes CSS Codes

.playlist { margin-top: 40rem; background: #ddd; padding: 2rem; width: 100; max-width: 30rem; margin: 40rem auto 0 auto;
}

LazyLoad.js Example - Script Codes JS Codes

var LazyLoad = function(opts) { var opts = opts || {}; this.options = { parent: opts.parent || '.lazyload', childs: opts.childs || 'img', attr: opts.attr || 'data-src', offset: opts.offset || 200 } this.parent = document.querySelector(this.options.parent); this.childs = this.parent.querySelectorAll(this.options.childs);
}
LazyLoad.prototype.init = function() { this.checkOffset(); this.bindScroll();
}
LazyLoad.prototype.checkOffset = function() { var viewportHeight = window.innerHeight; var windowOffset = (window.scrollY > 0) ? window.scrollY : 0; var childs = this.childs; var offsetBounce = viewportHeight; var childsLen = this.childs.length; if(this.parent.offsetTop - offsetBounce <= windowOffset) { for(var i = 0; i <= childsLen - 1, cur = childs[i]; i++) { // check if the current element needs to be displayed. if(cur.offsetTop - offsetBounce <= windowOffset) { if(cur.dataset.src !== '') { cur.src = cur.dataset.src; cur.dataset.src = ''; } } } }
}
LazyLoad.prototype.bindScroll = function() { window.addEventListener('scroll', function() { this.checkOffset(); }.bind(this))
}
var soundcloud_options = { childs: 'iframe', parent: '.playlist'
}
var soundcloud_slowpoke = new LazyLoad(soundcloud_options).init();
LazyLoad.js Example - Script Codes
LazyLoad.js Example - Script Codes
Home Page Home
Developer Kevin Gimbel
Username kevingimbel
Uploaded September 08, 2022
Rating 3
Size 2,537 Kb
Views 26,312
Do you need developer help for LazyLoad.js Example?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Kevin Gimbel (kevingimbel) Script Codes
Create amazing video scripts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!