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