Skip to content Skip to sidebar Skip to footer

How To Show Loading Gif While Image Preview Loading Via Javascript

On my page i am using links with image preview. When you go on link with mouse it show a preview image. Here is demo : http://cssglobe.com/lab/tooltip/03/ i want to show loading gi

Solution 1:

You could use a variation of the following code snippet to trigger an event once it's loaded:

var img = $("<img />").attr('src', 'http://somedomain.com/image.jpg')
    .load(function() {
        if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
            alert('broken image!');
        } else {
            $("#something").append(img);
        }
    });

Post a Comment for "How To Show Loading Gif While Image Preview Loading Via Javascript"