views:

435

answers:

3

Im using a preloader to load large images before I display them.. I am using this script:

http://davidwalsh.name/mootools-image-preloading-progress-bar

I want to make it disappear when it reaches 100% loaded. I have modified the script by adding

progressBar.set(0);

to the onComplete function at the bottom of the page. However, now the loader just fails to appear at all. How do I get the loader to disappear when it reaches 100%? Any ideas? Here is the rest of the script:

window.addEvent('domready', function() {

    var progressBar = new dwProgressBar({
        container: $('progress-bar'),
        startPercentage: 0,
        speed:750,
        boxID: 'box',
        percentageID: 'perc',
        displayID: 'text',
        displayText: false
    });


    var images = ['http://designvillain.com/logo_big3.jpg'];
    var loader = new Asset.images(images, {
        onProgress: function(counter,index) {
            progressBar.set((counter + 1) * (100 / images.length));
        },
        onComplete: function() {
            images.each(function(im) {
                new Element('img',{ src:im, style:'' }).inject($('images-holder'));

            });
        }
    });
});
A: 

you could always do:

$("progress-bar").empty();
// or .dispose(); or .destroy();
Dimitar Christoff
A: 

Dispose the element holding the progress-bar itself should work:

bar = $("progress-bar").dispose()

So you can reuse it later. Or hide it by

$("progress-bar").setStyle('display', 'none');
Enrico Carlesso
I tried what you suggested but I suspect there is some bigger issue lurking here. The progress bar doesn't show up until the image is 100% loaded. Firebug isn't returning an error so I am not sure what is going on. When I add any of the solutions you guys suggested, the bar doesn't show up at all. I suspect thats because its not looping until the image is done loading and then the bar is disappearing because the image is already 100% loaded.You can check it out here: http://designvillain.com
Thomas
Adding something like `console.log(counter)` in the onProgress function does show up something?
Enrico Carlesso
Wait a moment, at the link you provide I actually _can_ see the progress bar growing, and fullfilling the width. Didn't you?
Enrico Carlesso
Watch carefully, it doesn't start expanding until it the image is displayed. Then it just expands from 0 to 100. I removed the bit that hides it once it hits 100% loaded since this caused it to disappear entirely. I suspect if I can solve this problem with the progress bar animation running after the image finishes loading then the suggestions above should totally work.
Thomas
A: 

I think you may have a wrong expectation of David Walsh's image preloader. It does not show progress as an individual image is downloading, rather updates based on the percentage of an image set which has downloaded (ie 3 of 7 images rather than 20% of 1 image). So what you are getting is 0 progress initially then (1 of 1 or 100%) progress when the 1 image has been downloaded.

Randy Gibbs