Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does imagesLOaded not fire when the src attribute of an img element is changed with javascript? #136

Open
k-risc opened this issue Mar 11, 2014 · 6 comments

Comments

@k-risc
Copy link

k-risc commented Mar 11, 2014

I am using imagesloaded.pkgd.min.js and use the following javascript:

    …
$('#payable-preview a .overlay').show();
$('#payable-preview a img')
    .attr('src', …);
$('#payable-preview a img').imagesLoaded()
    .always(function() {
        $('#payable-preview a .overlay').hide();
    });

But the function defined in "always()" is triggered immediately each time this code is executed. Thus the overlay is never visible because it gets hidden right after it was shown.

@yairEO
Copy link

yairEO commented Apr 23, 2014

maybe try wrapping the imagesLoaded call with a setTimeout with like 10ms?

@saumets
Copy link

saumets commented Apr 29, 2014

I'm having this issue as well but in my situation I am completely replacing an img tag with a new one containing a different src image using jquerys replaceWith(). Am using imagesLoaded after the replaceWith() call to fire a new "fade-in" effect once the image is loaded. It seems to occur randomly but sometimes imagesLoaded seems to just instantly fire its complete/always message, leading to me getting an incorrect height calculation (0px) on the container w/ the new image.

is the setTimeout the way to go?

EDIT: I wrapped a setTimeout with a 100ms delay around my imagesLoaded call and everything seems to be working now. Hrmph?

@0xadri
Copy link

0xadri commented Nov 20, 2014

@skalfyfan do you have a live demo for this bug (a jsbin or jsfiddle) ?

@yairEO
Copy link

yairEO commented Nov 20, 2014

Actually imagesloaded fails rarely, but the reason is unknown. Sometimes I use setTimeout as a failsafe but it's an ugly hack.

@0xadri
Copy link

0xadri commented Nov 20, 2014

@k-risc The answer to your question, in short: Yes, imagesLoaded does not fire when the src attribute of an img element is changed with javascript, this happens with Firefox. see #121

Until the workaround mentioned in this issue is fully tested, you're probably "safer" by using imagesLoaded only on newly added images element.

@0xadri
Copy link

0xadri commented Nov 20, 2014

@yairEO you more details regarding this on #121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants