繁体   English   中英

如何在javascript中加载html5时停止一个函数并设置其他函数运行

[英]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>

我有两个功能,一个是预加载,另一个是加载图像。 两个函数都成功运行但我想要的是停止预加载功能来执行,并在完成图像加载时显示下一个函数。

简单地说,我想隐藏预加载函数并在加载精灵函数后显示精灵函数

看看这个: 等待图像加载后再继续

这是一个简单的模型:

<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>

并根据您的代码在PasteBin上另一个模型: http ://pastebin.com/wcBY2YaL

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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