npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-recliner

v0.2.5

Published

Lightweight plugin for lazy loading images and dynamic content

Downloads

209

Readme

Recliner.js

Recliner is a super lightweight (1KB) jQuery plugin for lazy loading images, iframes and other dynamic (AJAX) content. Being lazy never felt so good, just hook it up, and start sippin' those margaritas!

The script was born out of necessity when one of our clients came to us with massive scroll lag on one of their media heavy mobile news sites. It turned out that lazy-load-xt was the culprit, so naturally we tested the other lazy load scripts out there but none of them met our simple criteria:

  • Lightweight
  • Sets stateful CSS classes on elements
  • Ability to override event callbacks for custom behaviour
  • Can load any dynamic content (images, iframes, AJAX)
  • Mobile friendly
  • Printer friendly

Recliner is currently used on some very high traffic sites, so it's well tested and production ready.

Demo

For more information and a live demo see the project page: http://sourcey.com/recliner

Installation

If you use bower then type:

bower install recliner

Or if you like using npm then go ahead and type:

npm install jquery-recliner

Otherwise, just download recliner.min.js and stick it in your assets folder :)

Usage

Add jQuery (2.x or 1.x) and Recliner to your HTML source:

<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="recliner.min.js"></script>

Bind Recliner on elements with the .lazy class:

$(".lazy").recliner({
    attrib: "data-src", // selector for attribute containing the media src
    throttle: 300,      // millisecond interval at which to process events
    threshold: 100,     // scroll distance from element before its loaded
    printable: true,    // be printer friendly and show all elements on document print
    live: true          // auto bind lazy loading to ajax loaded elements
});

You can also progrmatically trigger an update to check for new elements to be loaded:

$(window).trigger("lazyupdate");

Recliner can be used to load a range of different dynamic content.

Images

Note: It's a good idea to specify image dimensions explicitly so your page height doesn't go berserk as lazy content is loaded into the DOM.

<img src="some-placeholder-image.png" data-src="image-to-lazy-load.png" class="lazy" width="333" height="333" /> 
Iframes
<iframe data-src="http://sourcey.com" width="333" height="333" class="lazy" frameborder="0" vspace="0" hspace="0"></iframe>
AJAX
<div data-src="http://sourcey.com" class="lazy" style="width:333px;height:333px">
    Loading, be patient damnit!
</div>

Callback API

Recliner exposes a simple event based API so you can implement your own custom behaviour using callbacks:

lazyload

The lazyload event will be triggered on elements that are about to be loaded.

$(document).on('lazyload', '.lazy', function() {
    var $e = $(this);
    // do something with the element to be loaded...
    console.log('lazyload', $e);
});
lazyshow

The lazyshow event will be triggered on elements after they have been loaded.

$(document).on('lazyshow', '.lazy', function() {
    var $e = $(this);
    // do something with the loaded element...
    console.log('lazyshow', $e);
});

Styling and Animations

Recliner will set the following stateful CSS classes on your elements:

  • lazy-loading: Set while the element is being loaded
  • lazy-loaded: Set when the element has loaded

Using the stateful classes you can add some fancy transitions to your images:

img {
  opacity: 0;
  transition: opacity .333s ease-in;
}

img.lazy-loaded {
  opacity: 1;
} 

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Issues

If you find any bugs please use the Github issue tracker.