Show Loading.gif Before Starting Script
I am using a script which takes some time to load, so I want to show a loading.gif image while the user is waiting. When I looked up how to do this, I came up with something like t
Solution 1:
I usually just do something like this:
$('#divWhereContentIsLoaded').hide().html('<img src="loading.gif" />').fadeIn().load('thingToLoad.php', {}, function(){
//something to do after it is loaded?
});
Hope this helps ;)
Solution 2:
css
.loading {position:center;
top:300px;
background-color:white;
padding:20px;
margin-left:45%;
background-image:url('visualisation-arbor/loading36.gif')}
html
<div><divclass="loading" ></div><canvasclass="explore_area"id="viewport"></canvas></div>
javascript, load function is asynchronous
//requires jquery > 1.5
$(document).ready(function(){
// wrap the Asynchronous load call in a deferred objectvar wrapperFunction = functionwrapLoader(deferred){
jOWL_loader.load();
//flags the load as done.
deferred.resolve();
//return the promise object, so we can chain events off this entirely asynchronous functionreturn deferred.promise();
};
//create a deferred object, asynchronous//passes the newly created Deferred object as the first param to the function wrapLoadervar ourDeferred = $.Deferred(wrapperFunction);
// when the promise object's listener registers the 'deferred.resolve()' call, execute our done function.
$.when(ourDeferred ).done(function(){
$('div.loading').toggleClass("loading");
}).done( function(){
var loaded = jOWL_loader.get();
visualize(loaded);
});
});
Post a Comment for "Show Loading.gif Before Starting Script"