码迷,mamicode.com
首页 > Web开发 > 详细

js 预加载

时间:2015-10-01 20:27:28      阅读:166      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!