Do something if an image is not loaded (jquery) -



Do something if an image is not loaded (jquery) -

i'm looking fade in background image when visitor arrives @ site not when they've got image in cache. along lines of this:

check if background image in cache. if show it. if isn't hide , when loads, fade in.

using jquery can hide , fade in when loads:

$("#bkg img").hide(); $('#bkg img').load(function() { $(this).fadein(); });

but how create conditional happens if image isn't cached?

everything i've found on forums triggers when image finishes loading. how can trigger because isn't loaded?

thanks help, lernz

@sima based on code that other thread i've made far next - doesn't seem having effect. if can see i'm going wrong that'd great:

var storage = window.localstorage; if (!storage.cachedelements) { storage.cachedelements = ""; } function logcache(source) { if (storage.cachedelements.indexof(source, 0) < 0) { if (storage.cachedelements != "") storage.cachedelements += ";"; storage.cachedelements += source; } } function cached(source) { homecoming (storage.cachedelements.indexof(source, 0) >= 0); } var plimages; //on dom ready $(document).ready(function() { plimages = $("#fundo-1 img"); //log cached images plimages.bind('load', function() { logcache($(this).attr("src")); }); //display cached images plimages.each(function() { var source = $(this).attr("src") if (!cached(source)) { $(this).hide().fadein(); } }); });

you can try:

if(!$('#bkg img')[0].complete) { $('#bkg img').hide().load(function () { $(this).fadein(); }); }

https://developer.mozilla.org/en/dom/htmlimageelement

jquery image load onload

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -