Hinzufügen spinner, während neue Bild geladen wird vollständig

Die Rolle, das Drehbuch zu ändern image.jpg mit newimage.gif und Umgekehrt, wenn auf Sie geklickt wird.

Jetzt möchte ich hinzufügen, ein spinner, während die newimage.gif Lasten.

So etwas wie auf 9gag.com/gif .


Kann mir bitte jemand helfen?

Dies ist der code:
html -

<img src="/image.jpg" id="pic" onclick="change()"/>
<a id="first" href="/newimage.gif" style="display:none;"></a>
<a id="second" href="/image.jpg" style="display:none;"></a>

javascript

function change(){
var imag = document.getElementById('pic').src;
var img = imag.slice(-3);
var img1 = document.getElementById('second').href;
var imag2 = document.getElementById('first').href;

if(img == 'gif') {
document.getElementById('pic').src=imag2;
//   here the newimage.gif changes to image.jpg 
} else {
//   here the image.jpg changes to newimage.gif
//   i think here should be the code that will display a spinner while the image.gif loads completely
document.getElementById('pic').src=img1;
}
}
InformationsquelleAutor Marian07 | 2014-01-21
Schreibe einen Kommentar