GithubHelp home page GithubHelp logo

andrzejpolis / waitforimages Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexanderdickson/waitforimages

0.0 1.0 0.0 199 KB

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

Home Page: http://alexanderdickson.com

License: MIT License

JavaScript 100.00%

waitforimages's Introduction

#waitForImages 1.4.2#

Copyright (c) 2011-2013 Alex 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 images referenced in CSS, such as the background-image property.

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

##Download##

##Usage##

###Standard###

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

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

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');
});

You can also set the third argument to true if you'd like the plugin to iterate over the colleciton and all descendent elements, checking for images referenced in the CSS (by default, it looks at the background-image, list-style-image, border-image and border-corner-image 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
});

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 a custom selector, :uncached, which when used in conjunction with the img selector, allows you to select img elements that are not cached already by the browser.

$('img:uncached').attr('title', 'Loading Image');

##Thanks##

##Feedback##

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

waitforimages's People

Contributors

alexanderdickson avatar mscharley avatar andrzejpolis avatar zerkms avatar

Watchers

 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.