Skip to content

Most Lazy loading libraries force you to change src to data-src and use a fake/empty image in src. But this library can provide a Lazy Loading feature without changing your image or document elements. Pure JavaScript without JQuery or extra code.

License

Notifications You must be signed in to change notification settings

BaseMax/LazyLoadingJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lazy Loading JS

Most Lazy loading libraries force you to change src to data-src and use a fake/empty image in src. But this library can provide a Lazy Loading feature without changing your image or document elements.

Pure JavaScript without JQuery or extra code.

Demo: https://basemax.github.io/LazyLoadingJS/

Using

<script type="text/javascript" src="https://basemax.github.io/LazyLoadingJS/lazyloading.js"></script>

Example

<script type="text/javascript">
var lazyloading = LazyLoading({
    'selector': 'img',
    'attribute': 'data-src'
});
</script>

Or

<script type="text/javascript">
document.querySelectorAll("img").forEach(img => {
  const src = img.getAttribute("src");
  if (src !== null) {
    img.setAttribute("data-src", src);
    img.setAttribute("src", "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
  }
});

var lazyloading = LazyLoading({
    'selector': 'img',
    'attribute': 'data-src'
});
</script>

© Copyright Max Base, 2022

About

Most Lazy loading libraries force you to change src to data-src and use a fake/empty image in src. But this library can provide a Lazy Loading feature without changing your image or document elements. Pure JavaScript without JQuery or extra code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published