2012-04-13 9 views
1

ich diese Situation haben:jQuery, ändern Bild src mit Lade Bild

<div id="main_image"> 
<img src="images/big_image.png" alt="big image" width="300" height="300" /> 
</div> 
<div id="thumbnails"> 
<a href="images/big1.png"><img src="images/thumb1.png" alt="thumb 1" /></a> 
<a href="images/big2.png"><img src="images/thumb2.png" alt="thumb 2" /></a> 
<a href="images/big3.png"><img src="images/thumb3.png" alt="thumb 3" /></a> 
</div> 

ich das große Bild src wie dieser Code ändern:

$("#thumbnails a").hover(function() { 
$("#main_image img").attr("src",$(this).attr("href")); 
}); 

Bevor das neue Bild zeigt, möchte ich zeigen, auf der main_image div ein Ladebild, wie dieses Skript, wenn das neue Bild zu groß ist, muss ich warten, um zu rendern. Wie kann ich diese Situation lösen?

Tnx


FOUND IT:

$('#additionals_image_carousel li a').mouseover(function() { 
      var href = $(this).attr("href"); 

      $("#productMainImage img").fadeOut(function() { 
       $(this).load(function() { $(this).fadeIn(); }); 
       $(this).attr("src", href); 
      }); 
    }); 

und #productMainImage hat eine Lade Bild als zentriert Hintergrund

jQuery fade to new image

+1

http://stackoverflow.com/questions/4635388/how-to-display-loading-image-while-actual-image-is-downloading – billyonecan

+0

Wie http integrieren: // Stackoverflow .com/questions/4635388/how-to-display-loading-image-während-aktuelles-bild-herunterladen mit meinem beispiel? – benzo

Antwort

0

ich es nicht getestet, sondern geben ihm eine versuch, platziere dieses div im Hauptbild

<div id="load"><img src="images/loading.gif"/></div> 

#load 
{ 
display:none; 
} 

tun dann so etwas wie dieses

$("#thumbnails a").hover(function() { 
$("#load").css('display','inline'); 
}); 
+0

Ich möchte das Laden von Bildern vor der Show zeigen. Vervollständige das gerenderte Bild, zeige nicht nur ein Div mit geladenem Bild. Ich möchte so etwas tun http://stackoverflow.com/questions/4635388/how-to-display-loading-image-while-actual-image-is-downloading aber ich weiß nicht die beste Art und Weise für meine Arbeit Beispiel. – benzo

+0

@benzo hast du es versucht, was passiert, wenn du das tust – freebird

+0

Kannst du die neue Lösung überprüfen, die ich am Post geändert habe? Es funktioniert nicht auf ie7 :( – benzo

0
  1. Laden GIF-Bild hinzufügen
  2. ordne nicht den Laden jedes Mal Aktin die Mouseover-Aktin gefeuert

html:

<img id="loading" src="/images/loading.gif" style=" display: none;"/> 

js:

var img = $("#productMainImage img"); 
var loadImg = $("#loading"); 

$('#additionals_image_carousel li a').mouseover(function() { 
    img.hide(); 
    loadImg.show(); 
    img.attr("src", $(this).attr("href")); 
}); 

img.load(function() { 
    loadImg.hide(); 
    $(this).fadeIn(); 
});