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

@staaky/voila

v1.5.2

Published

A jQuery plugin that provides callbacks for images, letting you know when they've loaded.

Downloads

3

Readme

Voilà

Voilà is a jQuery plugin that provides callbacks for images, letting you know when they've loaded.

voila.nickstakenburg.com

Voilà has an API inspired by imagesLoaded, extended with useful methods like abort() and support for naturalWidth and naturalHeight in all browsers, which makes it compatible with IE6 & IE7. Multiple loading methods are supported, allowing callbacks to fire as soon as naturalWidth is available, making Voilà faster than alternatives that wait for onload to fire.

Install

Get a packaged source file:

Include Voilà below jQuery:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="voila.pkgd.min.js"></script>

Alternatively Voilà can be installed using Bower or npm:

bower install voila
npm install @staaky/voila

Usage

$(element).voila([options][, callback]);
// For example
$('#container').voila(callback);
$('#container').voila({ method: 'onload' }, callback);
  • options - Object - (optional) An object with Options
  • callback - Function - (optional) A function called when all images have been loaded

Using a callback is the same as using always():

$('#container').voila().always(callback);

Additional callbacks can be attached using always(), progress(), fail() and done():

$('#container').voila()
  .always(function(instance) {
    console.log('ALWAYS - All images have finished loading');
  })
  .progress(function(instance, image) {
    var status = image.isLoaded ? 'loaded' : 'broken';
    console.log('PROGRESS - Image ' + status + ': ' + image.img.src);
  })
  .fail(function(instance) {
    console.log('FAIL - All images finished loading, but some are broken');
  })
  .done(function(instance) {
    console.log('DONE - All images finished loading succesfully');
  });

Options

Options can be set as the first parameter.

  • method - String - The loading method, the default is 'onload' which calls callbacks as soon as onload fires. The alternative is 'naturalWidth', which calls callbacks as soon as naturalWidth is available, images will have dimensions at that point but could still be rendering. Don't use 'naturalWidth' when changing the src attribute of an image, it becomes unreliable at that point. Use 'onload' instead in those cases.
// callback as soon as naturalWidth & naturalHeight are available
$('#container').voila({ method: 'naturalWidth' }, function(instance) {
  $.each(instance.images, function(i, image) {
    var img = image.img;
    console.log(img.src + ' = ' + img.naturalWidth + 'x' + img.naturalHeight);
  });
});

// give images more time to render by waiting for onload (default)
$('#container').voila({ method: 'onload' }, function(instance) {
  console.log('All images have finished loading');
});

API

A voila instance can be stored, exposing some extra properties and functions:

var voila = $('#container').voila();
  • voila.images - Array - Contains an image object for each img element found
  • voila.abort() - Aborts all callbacks
  • voila.always(callback) - Add a callback called after all images finished loading
  • voila.progress(callback) - Add a callback called as each image finishes loading
  • voila.fail(callback) - Add a callback called if one or more images fail to load
  • voila.done(callback) - Add a callback called after all images have succesfully loaded

Within the callbacks the voila instance is always the first argument, the second one can be an image object.

  • image.img ImageElement - The img element as found in the DOM
  • image.isLoaded Boolean - true when succesfully loaded

Here's how to find out which images have succesfully loaded within the always callback:

$('#container').voila(function(instance) {
  $.each(instance.images, function(i, image) {
    var status = image.isLoaded ? 'loaded' : 'broken';
    console.log(status + ': ' + image.img.src);
  });
});

License

Voilà is MIT Licensed.


By Nick Stakenburg