GithubHelp home page GithubHelp logo

jacobfitzp / lazyimage Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 29 KB

Simple package for quick and easy image lazyloading. Helps improve the performance of your front-end and reduce the total resources you are serving to the user by only loading in images as and when they are actually needed.

License: MIT License

JavaScript 100.00%
lazyload lazyload-images

lazyimage's Introduction

LazyImage

LazyImage.js enables easy and effective lazyloading of images.

Powered by @jacobfitzp/viewport-helper it ensures images are only loaded when inside the viewport, cutting down loadtimes and resource sizes.

Installation

NPM

npm install @jacobfitzp/lazyimages

Once installed, you can require the package using:

require('@jacobfitzp/lazyimages');

CDN

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@jacobfitzp/[email protected]/dist/lazyimages.min.js"></script>

Usage

To use simply add the lazyload class to the element you wish to lazyload, and unset the src, making sure to instead set data-src or data-srcset

<!-- Example Image Element -->
<img class="lazyload" data-src="/image.jpg" alt="Lazyloaded Image" />

<!-- Example "other" element, will apply background image -->
<div class="lazyload" data-src="/image.jpg"></div>

Once loaded the lazyload class is removed and replaced with a lazyloaded class, you can use this to apply custom transitions such as fading in images.

Initialisation

LazyImage only applies lazyloading automatically to elements that are present on DOMContentLoaded, this means if additional elements are added after load you will need to reinitialise lazyloading yourself, this can easily be done by doing:

LazyImage.init();

lazyimage's People

Contributors

jacobfitzp avatar

Watchers

 avatar

Forkers

pkdigital

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.