jQuery: .load image, then fadeIn() fails when clicked twice! -
so i've got .load setup image .fadein() callback, works fine. problem if fire .load twice in row on same image, doesn't callback!
here's snippet of code:
$('#thumbs a').click( function() { imagesrc = $(this).attr('href').substring(1)+'.jpg'; // grab src, remove hash, add jpeg extension $('#viewer img').fadeout('fast', function() { // fade old image out fast, wait until finished before changing src $('#viewer img').attr('src', (mediumpath+imagesrc)); // change src new image $('#viewer a').attr('href', imagesrc); }); $('#viewer img').load(function(){ // once image loaded, fade img in $('#viewer img').fadein('slow'); }); return false; });
and can try on website (in progress) here. click on thumbnail on left twice in row , loader.gif doesn't go away, i.e. not getting .fadein().
note: i believe affecting webkit browsers(?)
i have tested site http://www.benjibee.com/ in chrome (webkit-based browser, far know), , have been unable replicate problem. although take little longer in firefox (but may computer).
a couple of suggestions/observations.
with .click()
based interactions, using format:
.click( function( e ) { e.preventdefault(); // rest of javascript code here... } );
will stop anchor/link performing such, , can evoked @ start of jquery processing, rather waiting end use return false
.
you may want store in javascript variable details of current image/link, , check against on subsequent clicks on thumbnails - stands, if img1.jpg
shown, , thumb image clicked, current larger image fades out, , fades in again no change. tiny thing.
Comments
Post a Comment