Comments (4)
There was an issue with recently added even caching feature, which did not take into account changed src, so it reported images with new src as already loaded. Should be fixed, but please test it just to be sure :)
from imagesloaded.
Unfortunately the fix does not work for my demo. imagesloaded() gets fired, but still too soon: when reading the width of the image, it returns the width of the previous image. The timed out check prints out the right width. I uploaded the new jquery.imagesloaded.js, check it at http://www.wishdesign.nl/fora/imagesloaded/problem.htm.
My solution with replacing the actual image for a clone seems to solve this, but has a big disadvantage: the old image gets removed, a new one gets inserted. So any jQuery collections made earlier contain a reference to the old image... imagesloaded() could return the new image elements, but this is not ideal.
from imagesloaded.
After looking at your demo, of course it gets fired too soon :) It seems that you've misunderstood the imagesLoaded functionality. ImagesLoaded checks whether every image in current stack at current time has finished loading, and if it does, it triggers a callback (and resolves deferred object). If it doesn't, it waits for it to finish, and than fires callback (and resolves dfd).
What you are doing, is that you are checking whether an image has finished loading BEFORE you change its src. Obviously the code in callback can't return the new width, because it is called before you've even changed the src :)
In other words, imagesLoaded is called on an image with old src, which is already loaded, thus it immediately fires callback, and THAN you change its src :)
Quick fix for you:
// Current wrong usage
$img.imagesLoaded( fn ).attr('src' , (nr=nr==1?2:1) + '.jpg');
// Fixed
$img.attr('src' , (nr=nr==1?2:1) + '.jpg').imagesLoaded( fn );
from imagesloaded.
You are so right! My initial code was in the right order, then I ran into the "event caching was ignoring changed img.src" problem (solved by fix at 695f896) and built a test page with the wrong order. I guess I treated imagesloaded() as an event: I wanted to attach it before the source change to be sure the image could not get loaded without the 'event'.
As proof I posted the initial demo, with your fixed jquery.imagesloaded.js and the right order at: http://www.wishdesign.nl/fora/imagesloaded/problema.htm. Works like a charm! :-) Thanks a lot for the effort!
Cheers from the Netherlands
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.