首页 > Web开发 > 详细

js 预加载

时间:2015-10-01 20:25:47      阅读:257      评论:0      收藏:0      [点我收藏+]
01.window.onload = function() {

02.

03.    setTimeout(function() {

04.       

05.// reference to <head>

06.        var head = document.getElementsByTagName(‘head‘)[0];

07.

08.        

09.// a new CSS

10.        var css = document.createElement(‘link‘);

11.        css.type = "text/css";

12.        css.rel  = "stylesheet";

13.        css.href = "http://domain.tld/preload.css";

14.        

15.// a new JS

16.        var js  = document.createElement("script");

17.        js.type = "text/javascript";

18.        js.src  = "http://domain.tld/preload.js";

19.        

20.// preload JS and CSS

21.        head.appendChild(css);

22.        head.appendChild(js);

23.         

24.// preload image

25.        new Image().src = "http://domain.tld/preload.png";

26.

27.    }, 1000);

28.

29.};

 

js 预加载

原文:http://www.cnblogs.com/yangxu6069/p/4851397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!