Simple jQuery extension for dynamically loading images while scrolling. Intended for image-heavy websites to save bandwidth and decrease intial load time.
Include the latest version of jQuery and jQuery.loadScroll.js
in the <head>
of your HTML document:
<script src="jQuery.min.js"></script>
<script src="jQuery.loadScroll.js"></script>
Reference the loadScroll()
method and use the data-src
attribute for all dynamic loading images. The data-src
changes to the standard src
attribute as the image(s) enter the viewport. Placeholder images are optional. See the live demo: code.nath.co/loadScroll
HTML
<!-- Load on Scroll -->
<img id='1' data-src="a.png" src="#" alt="">
<img id='2' data-src="b.png" src="#" alt="">
<img id='3' data-src="c.png" src="#" alt="">
<img id='4' data-src="d.png" src="placeholder.png" alt="">
jQuery
$(function() {
// Default
$('img').loadScroll(0,2);
// Custom fadeIn Duration
// 2 It's Number Of Image Load Before Scroll
$('img').loadScroll(500,2);
});
– Google Chrome
– Safari ( Desktop & Mobile )
– Internet Explorer ( 8, 9, 10+ )
– Firefox
– Opera ( Not Tested )
jQuery.loadScroll 1.0
– Initial Release
jQuery.loadScroll 1.0.1
– Changed isrc
attribute to data-src
for HTML validation
– Added paramater for fadeIn
duration
If you discover any issues or have questions regarding usage, please send a message to [email protected] or find me on GitHub @nathco.