noviceRick
noviceRick

Reputation: 121

jQuery image reloader function?

I do have a gif image load bar animation I do want it to reload when click Reload Image so that the animation will repeat.

//My HTML
<img src="http://i54.tinypic.com/2qdwtp0.gif" id="load-bar"/>
<a href="#" id="reloadImg">Reload Image</a>

//My js code

function imgRelaoder() {
//some stuff to reload image with id #load-bar
}    

$(function() {
    imgRelaoder();
    $("#reloadImg").click(imgRelaoder);
});

Upvotes: 1

Views: 697

Answers (3)

sanmai
sanmai

Reputation: 30891

function imgRelaoder() {
    $("#load-bar").attr("src", 
        $("#load-bar").attr("src")
    );
}    

Upvotes: 0

T Nguyen
T Nguyen

Reputation: 3415

First, create an Image object and assign it a src property:

    var image = new Image();
    image.src = "path-to-your-loader.gif";

Then, in your function imgReloader:

    $("#load-bar").attr("src", image.src);

Upvotes: 0

user113716
user113716

Reputation: 322492

$(function() {
    var loadImg = document.getElementById('load-bar');

    $("#reloadImg").click(function() {
        loadImg.src = loadImg.src;
    }).click();
});

http://jsfiddle.net/27NV3/

Upvotes: 2

Related Questions