Giter Site home page Giter Site logo

Comments (4)

darsain avatar darsain commented on June 12, 2024

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.

lmeurs avatar lmeurs commented on June 12, 2024

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.

darsain avatar darsain commented on June 12, 2024

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.

lmeurs avatar lmeurs commented on June 12, 2024

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)

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.