Giter Club home page Giter Club logo

whtevr's Introduction

whtevr Build Status

The lazy loading library that just doesn't care.

whtevr is a lazy loading library that can lazily load anything. I designed it so that I could use it with srcset and picturefill. You can probably put other stuff like videos in it, too. Whatever. I don't care. Neither does this library.

It relies on jQuery and another library of mine, when-scroll.

Installation

$ npm install --save whtevr

Usage

Put everything in a noscript tag with the class "js-whtevr":

<noscript class="js-whtevr">
	<img src="..." srcset="...">
</noscript>

It will load the contents of the script tag when it is 300px away from the bottom of the screen.

You can also use it to defer the loading of stuff until after the page has loaded, using the data-load-after attribute. It doesn't matter where it is: if you specify this attribute, it will be loaded after that amount of time.

An event will be fired when it is loaded:

$('.js-whtevr').on('whtevr-loaded', function (e, $el) {
	picturefill({
		elements: $el.toArray()
	});
});

An additional event will be fired when the images contained are all loaded:

$('.js-gallery').on('whtevr-images-loaded', function (e, $el) {
  initGallery($el);
});

jQuery plugin

The library also includes a jQuery plugin that you can use to immediately load the contents of a whtevr element:

$('.js-whtevr').whtevrLoad();

legacy

Prior to 0.2 (and this still works), you had to use a script tag:

Put everything in a script tag with the type "text/x-whtevr":

<script type="text/x-whtevr">
	<img src="..." srcset="...">
</script>

It will load the contents of the script tag when it is 300px away from the bottom of the screen.

You can also use it to defer the loading of stuff until after the page has loaded, using the data-load-after attribute. It doesn't matter where it is: if you specify this attribute, it will be loaded after that amount of time.

An event will be fired when it is loaded:

$('[type="text/x-whtevr"]').on('whtevr-loaded', function (e, $el) {
	picturefill({
		elements: $el.toArray()
	});
});

As of 0.2, you can use noscript tags to lazy load stuff. It works without JavaScript, and it means your editor will syntax highlight the contents.

License

Released under the MIT license.

whtevr's People

Contributors

callumacrae avatar mrcthms avatar

Stargazers

Francois-Guillaume Ribreau avatar Sam Gluck avatar James Nicholls avatar Manu avatar Stefan Bohacek avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

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.