All Projects → alexanderdickson → Waitforimages

alexanderdickson / Waitforimages

Licence: mit
A jQuery plugin that lets you attach callbacks to useful image loading events.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Waitforimages

Jalert
jQuery alert/modal/lightbox plugin
Stars: ✭ 73 (-94.38%)
Mutual labels:  jquery-plugin
Ditherjs
A javascript library which dithers an <img> using a fixed palette
Stars: ✭ 76 (-94.14%)
Mutual labels:  jquery-plugin
Tui.calendar
🍞📅A JavaScript calendar that has everything you need.
Stars: ✭ 9,537 (+634.75%)
Mutual labels:  jquery-plugin
Jquery.toaster
jQuery plugin for displaying customizable toast notifications via Bootstrap alerts
Stars: ✭ 74 (-94.3%)
Mutual labels:  jquery-plugin
Tag Handler
Tag Handler is a jQuery plugin used for managing tag-type metadata.
Stars: ✭ 76 (-94.14%)
Mutual labels:  jquery-plugin
Bootstrap Strength Meter
Password strength meter based on Twitter Bootstrap and Password Score.
Stars: ✭ 79 (-93.91%)
Mutual labels:  jquery-plugin
Jquery Calendar
A responsive jquery calendar scheduler built with bootstrap and moment.js
Stars: ✭ 67 (-94.84%)
Mutual labels:  jquery-plugin
Popup Maker
Popup Maker plugin for WordPress
Stars: ✭ 87 (-93.3%)
Mutual labels:  jquery-plugin
Richtext
WYSIWYG editor developed as jQuery plugin
Stars: ✭ 77 (-94.07%)
Mutual labels:  jquery-plugin
Jquery Wizard
A powerful jquery plugin for creating step-by-step wizards. Work great with bootstrap.
Stars: ✭ 82 (-93.68%)
Mutual labels:  jquery-plugin
Swiftype Search Jquery
Elastic Site Search jQuery search plugin
Stars: ✭ 74 (-94.3%)
Mutual labels:  jquery-plugin
Applozic Web Plugin
Javascript (jQuery) Real Time Chat & Messaging plugin
Stars: ✭ 76 (-94.14%)
Mutual labels:  jquery-plugin
Jquery Mosaic
A jQuery plugin to build responsive mosaics of images or any other content fitted to match heights in multiple rows while maintaining aspect ratios. http://jquery-mosaic.tin.cat
Stars: ✭ 80 (-93.84%)
Mutual labels:  jquery-plugin
Tokenize2
Tokenize2 is a plugin which allows your users to select multiple items from a predefined list or ajax, using autocompletion as they type to find each item. You may have seen a similar type of text entry when filling in the recipients field sending messages on facebook or tags on tumblr.
Stars: ✭ 74 (-94.3%)
Mutual labels:  jquery-plugin
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (-3.62%)
Mutual labels:  jquery-plugin
Jquery Lockfixed
jQuery lockfixed plugin
Stars: ✭ 69 (-94.68%)
Mutual labels:  jquery-plugin
Jquery.ajax Combobox
jQuery plugin to create a text box which can auto-complete and pull-down-select.
Stars: ✭ 78 (-93.99%)
Mutual labels:  jquery-plugin
Jquery Slick Rails
Integrates Slick carousel, a jQuery plugin, into your Rails app.
Stars: ✭ 89 (-93.14%)
Mutual labels:  jquery-plugin
Promoslide
jQuery plugin for promotional content that appears with user scrolling
Stars: ✭ 86 (-93.37%)
Mutual labels:  jquery-plugin
Live Css Editor
jquery online css editor, themeroller like tool for customizing your web page
Stars: ✭ 80 (-93.84%)
Mutual labels:  jquery-plugin

waitForImages

Copyright (c) 2011-2018 Alexander Dickson @alexdickson

Licensed under the MIT licenses.

http://alexanderdickson.com

Donate!

Build Status

Overview

Provides useful callbacks once descendant images have loaded.

waitForImages also supports both images referenced in CSS, such as the background-image property, and images referenced in element attributes such as srcset. Images referenced in attributes can also be a comma-separated list of images.

It can be useful when WebKit incorrectly reports element dimensions/offsets on document ready, because it has not calculated their descendant img dimensions yet.

Supports all browsers you probably care about.

Get it

You can either grab the source yourself...

...or you can use a hosted version...

Alternatively, you can install with bower...

bower install waitForImages

...or npm...

npm install jquery.waitforimages

Of course, these need to be loaded after jQuery is made available. The current version should be supported by at least jQuery 1.8, or perhaps earlier. If you find incompatibility issues, please check out a previous tagged version.

Usage

There are two ways to use waitForImages: with a standard callback system (previously the only API) or receiving a promise.

Standard

Just provide a callback function and it will be called once all descendant images have loaded.

$('selector').waitForImages(function() {
    // All descendant images have loaded, now slide up.
    $(this).slideUp();
});

You can also use the jQuery promise API.

$('selector').waitForImages().done(function() {
    // All descendant images have loaded, now slide up.
    $(this).slideUp();
});

In the callbacks, this is a reference to the collection that waitForImages() was called on.

Advanced

You can pass a second function as a callback that will be called for each image that is loaded, with some information passed as arguments.

$('selector').waitForImages(function() {
    alert('All images have loaded.');
}, function(loaded, count, success) {
   alert(loaded + ' of ' + count + ' images has ' + (success ? 'loaded' : 'failed to load') +  '.');
   $(this).addClass('loaded');
});

Using the jQuery promises API, you can then use the progress() method to know when an individual image has been loaded.

$('selector').waitForImages().progress(function(loaded, count, success) {
   alert(loaded + ' of ' + count + ' images has ' + (success ? 'loaded' : 'failed to load') +  '.');
   $(this).addClass('loaded');
});

You can also set the third argument to true if you'd like the plugin to iterate over the collection and all descendent elements, checking for images referenced in the CSS (by default, it looks at the background-image, list-style-image, border-image, border-corner-image and cursor properties). If it finds any, they will be treated as a descendant image.

The callback will be called on the successful and unsuccessful loading of the image. Check the third argument to determine the success of the image load. It will be true if the image loaded successfully.

If you want to skip the first argument, pass $.noop or alternatively, pass an object literal to the plugin, instead of the arguments individually.

$('selector').waitForImages({
    finished: function() {
        // ...
    },
    each: function() {
       // ...
    },
    waitForAll: true
});

To use this with the promise API, simply pass one argument, which is waitForAll.

$('selector').waitForImages(true).done(function() {
    // ...
});

You may also set the CSS properties that possibly contain image references yourself. Just assign an array of properties to the plugin.

$.waitForImages.hasImgProperties = ['backgroundImage'];

waitForImages also exposes two custom selectors, img:has-src and img:uncached, (both used in conjunction with the img selector), which allow you to select img elements with a valid src attribute or that are not already cached already by the browser, respectively.

$('img').not(':has-src').remove();
$('img:uncached').attr('title', 'Loading Image');

Feedback

Please use the Issues for any bugs, feature requests, etc.

If you're having problems using the plugin, ask a question on Stack Overflow.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].