-
10.添加script标签,判断onload是否完成
- class Tools
- {
- static loadScript(url, callback)
- {
- let old_script = document.getElementById(url);
- if (old_script)
- {
- if (old_script.ready == true)
- {
-
- callback();
- return;
- }
- else
- {
- document.body.removeChild(old_script);
-
- }
- }
- let script = document.createElement('script');
- script.id = url;
- script.src = url;
- script.onload = script.onreadystatechange = function() {
- if (script.ready) {
- return false;
- }
- if (!script.readyState
- || script.readyState == "loaded" || script.readyState == 'complete'
- ) {
-
- script.ready = true;
- callback();
- }
- };
- document.body.appendChild(script);
- }
-
-
-
- static syncLoadScripts(scripts, callback)
- {
- var ok = 0;
- var loadScript = function(url) {
- Tools.loadScript(url, function(){
- ok++;
-
- if (ok == scripts.length) {
- callback();
- }
- else {
- loadScript(scripts[ok])
- }
- })
- }
- loadScript(scripts[0]);
- }
-
-
-
- static asyncLoadScripts(scripts, callback)
- {
- var ok = 0;
- for (var i=0; i < scripts.length; i++) {
- Tools.loadScript(scripts[i], function() {
- console.log(scripts[ok])
- ok++;
- if (ok==scripts.length)
- {
- callback();
- }
- })
- }
- }
- }
-
- export default Tools;
-
相关阅读:
234树(2)实现
矩阵的坐标变换(转)
OpenGL 学习笔记(3)绘制几何物体
OpenGL 学习笔记(1)初始化窗体
OpenGL学习笔记(5)3D基本概念
矩阵的三维变换(转)
OpenGL 学习笔记(2)创建第一个图形
234树(1)概念
OpenGL 学习笔记(4)顶点数组
OpenGL学习笔记(6)第一个动画
-
原文地址:https://www.cnblogs.com/wangrui38/p/9181633.html
Copyright © 2020-2023
润新知