Comments (12)
Am having the same issue! I thought I wasn't doing it right...
from imagesloaded.
Yeah unfortunately I'm seeing inconsistent results here too.
http://jsfiddle.net/BtHZu/6/
Only the last image is getting the border in Firefox and Safari.
http://jsfiddle.net/BtHZu/6/embedded/result/
Here Safari applies all the borders but again Firefox only applies it to the last image.
The imagesLoaded demo works perfectly but I'm curious as to if it's because the images are being appended to the DOM rather than being there from the start.
if ( hasNotify ) {
deferred.notifyWith( $(img), [ isBroken, $images, $(proper), $(broken) ] );
}
The deferred stuff is complete witchcraft to me, but I can see that the plugin gets inside the conditional but doesn't reliably fire the notifyWith() method.
from imagesloaded.
I've looked into it, and it actually works properly, it's just that .imagesLoaded()
in FF is so fast, that all images has been marked as loaded before you've even managed to bind .progress
handler :) And because .progress
doesn't work with past events as .done
, .fail
and .always
do, nothing happens... Oh you, asynchronicity, you... :)
So currently, there is no way how to make this work properly for you guys. This will require a change in .imagesLoaded()
structure that will support binding of .progress
method before the determination process starts.
But as I've mentioned, .done
, .fail
and .always
methods will work properly.
from imagesloaded.
So I've created a new branch defer that contains my solution to this problem. It introduces a new argument, called defer, that postpones determination process, and gives a user the '.start()' method to start it manually. Branch has updated demo page and documentation. It would be nice if @desandro could review the changes and perhaps raise some objections :)
from imagesloaded.
See SHA: 7eb2210
I think if we add another argument, we might as well add a proper options argument. In this case I changed defer
to options.isDeferringStart
. There's some munging that has to go on to ensure that callback
is still a proper function and this branch doesn't break backwards compatibility.
With this in mind - your thoughts?
from imagesloaded.
But but but, now it's so simple :( With only 2 arguments, both being optional, people who are interested only in callback can do:
$(selector).imagesLoaded( fn );
While people interested in deferred+progress can do:
var dfd = $(selector).imagesLoaded( true );
// ...
dfd.start();
I really don't like an options object with only one option :/ Especially when it unsimplifies things.
I understand that this is a "thinking of future", where we might be in a situation to implement more options, but that really doesn't seem likely for this plugin, so adding options object would be just annoying. And even in that highly unlikely situation, we would just bump up the mayor version (i.e. non-backwards-compatible update) and be done :)
from imagesloaded.
I guess a highlight? :) @desandro
from imagesloaded.
@darsain Sorry, this is on the my back-burner for a couple days. You bring up some good points. My issues are:
var dfd = $(selector).imagesLoaded( true );
- Wouldn't this break jQuery chainability? If this was how it was previously working, we should have a separate conversation about that
- This bit of code doesn't read to me as "oh, this is a deferred start thingie." If I were someone else looking at imagesLoaded for the first time, I would assume the
true
flag would be for something simpler, like triggering immediately or something.
from imagesloaded.
@desandro nope, the full jQuery object is always returned, just extended with deferred promise methods, and a .start()
method if postponed determination is requested (defer=true
argument), so you can still chain like:
var dfd = $(selector).imagesLoaded( true ).progress( fn ).css()...;
dsd.start();
But this example pointed out to me that checkImages()
, i.e. .start()
method should also return the full jQuery+deferred object, so we could chain even after that, like so:
$(selector).imagesLoaded( true ).progress( fn ).start().css()...;
I'll add it to my todo for the final 2.1.0 version.
The second point: actually, the call with defer=true
has nothing to do with jQuery Deferred object. It's just a similar word used for the second argument, and to avoid confusion, we could probably change it to postpone
or something. The deferred object is being returned as an extension of the original jQuery object whenever the imagesLoaded is working with jQuery 1.5+ (i.e. when jQuery.Deferred()
is present).
And what happens when you call .imagesLoaded( true )
is dictated by documentation, not feelings :) but we can play with semantics so it would make more sense. Like negating the meaning of the second argument from postpone
, to immediate
, where the default value would be true
, and if people would want to postpone the determination, they would call $(selector).imagesLoaded( false )
, which makes more sense?
from imagesloaded.
@darsain There is absolutely nothing intuitive about the whole .start()
magic going on in this discussion – that's an implementation-level detail I'd be happier not needing to know anything about as an API user.
Could we get away from that need by supporting an options argument that sets all the handlers we care about before you kick things off?
$(selector).imagesLoaded({ progress: fadeInMyImage
, done: cueTheAngelChoir
, fail: tootTheAngryHorn
});
Having it treat a function parameter as the done callback sounds like a friendly shorthand, but for the love of $deity avoid the boolean trap; it's almost invariably bad API design, and this is not an exception to that rule.
I'm sure I'm neither the first nor last to end up writing code like this, as it was easier to spot what broke and kludge past the breakage than figuring out that you can't trust the progress callback:
function sizeAvatars($imgs) {
function sizeOnceDimensionsKnown() { /* ... */ }
var $seen = $([]);
// see https://github.com/desandro/imagesloaded
$imgs.imagesLoaded().progress(
function (isBroken, $images, $proper, $broken) {
if (!isBroken) sizeOnceDimensionsKnown(this);
$seen = $seen.add(this); // don't redo below!
})
// Ugh: we're not guaranteed a .progress() callback for cached images?
.done(function($all) {
$all.not($seen).each(sizeOnceDimensionsKnown);
});
}
from imagesloaded.
@johan true. Your proposition is better :) So the new API would be:
Simple call with "on images done loading" callback
$images.imagesLoaded( function () {} );
Call registering deferred methods before the determination process starts
$images.imagesLoaded({
done: function () {},
fail: function () {},
progress: function () {}
});
Using the returned deferred object
var dfd = $images.imagesLoaded();
dfd.done( function () {} );
dfd.fail( function () {} );
dfd.progress( function () {} ); // note in documentation that this is unreliable
If @desandro has no objections, I'll implement that as soon as there would be some free time on my hand :)
from imagesloaded.
No objections. I like the options syntax.
👍
from imagesloaded.
Related Issues (20)
- It doesn't work with <picture> tag? HOT 1
- Including the imagesloaded.js library causes <source srcset> images to load two versions of the image, increasing bandwidth by ~4x HOT 2
- .bind deprecated HOT 1
- V3 site page not found HOT 2
- desandro.com has expired HOT 1
- Not working with only srcset HOT 5
- MIT License Page HOT 1
- Timing a page loader only to visible images using imagesLoaded [SOLVED] :) HOT 1
- Thanks for your library! HOT 2
- wp + masonry + imagesloaded lazyload = gap between posts HOT 2
- Multiple file type download issue with imagesLoaded, Barba and Swiper
- Some issues -
- Imagesloaded v5 triggers loading of largest image when using srcset HOT 5
- Downloads jpeg image when using picture element in browser that supports modern formats
- obj is not iterable HOT 2
- Warning: noob incoming HOT 1
- Run each function after each image is loaded instead of waiting for every image to load and run all functions at once HOT 2
- Public site is broken HOT 1
- Possible bug with makeArray helper function in 5.0.0 HOT 2
- Is there a way to check if at least one image is loaded?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imagesloaded.