简体   繁体   中英

How to stop a function and set other function to run when it loads in javascript for html5

<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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM