0
<script>
function start(){
    sprites.start();
    preloader();
    }
</script>

I am having two functions one to preload and other to load the image. Both functions running succesfully but what i want is stop preload function to execute and shows the next function when ever image loading is done.

Briefly i want to hide the preload function and show the sprite function after loading of sprite function

Villan
  • 730
  • 1
  • 8
  • 26

1 Answers1

2

Take a look at this: Wait for image to be loaded before going on

Here is a simple mockup:

<html>
<head>
<script language="javascript">
function loadImage()
{
  var img = new Image();
  img.src = 'img_navsprites.gif';
  console.log( '1. Image has just started downloading.' );
  document.getElementsByTagName('body')[0].appendChild(img);
  img.onload = function() {
    console.log( '2. Image has fully loaded.' );
  }
  console.log( '3. Hey, look at me ... all the way down here!' );
}
</script>
</head>
<body onload="loadImage()">
<div>
</div>
</body>
</html>

And a another mockup at PasteBin based on your code: http://pastebin.com/wcBY2YaL

Community
  • 1
  • 1
Dane Balia
  • 5,271
  • 5
  • 32
  • 57
  • No buddy still trying on the same @Dane Baila – Villan Aug 08 '12 at 05:01
  • The sample code I gave above works perfectly. If not, here is a jsfiddle http://jsfiddle.net/dane/B9J7E/15/ – Dane Balia Aug 08 '12 at 05:41
  • http://pastebin.com/h5N8aqkW please go through this.This is what i have done so far but both preloader and spritesheet appearing simulatneously i want to hide preloader after spritesheet loaded – Villan Aug 08 '12 at 05:49
  • This is what I've done in PasteBin. There are quite a few things I didn't understand, like how your functions were being called, as I didn't see any. anyways, here's a hack of your code. the main premise of what I was trying to do, was load your "CanvasLoader", and remove it when the image has fully downloaded. In this case, the image is 3.8MB and it works. http://pastebin.com/wcBY2YaL – Dane Balia Aug 08 '12 at 06:14
  • Cool, don't forget to VOTE :) – Dane Balia Aug 08 '12 at 09:55
  • what have to do if it is the case of other functions instead of images @DaneBalia – Villan Aug 08 '12 at 12:36