图片预加载方案
// 所有的图片(要是网络太好,自己加图片吧) const imgs = [ "{{ static_url('topic/aqiyi_test/img/intro.png') }}", "{{ static_url('topic/aqiyi_test/img/rwtf.png') }}", "{{ static_url('topic/aqiyi_test/img/rwwz.png') }}", "{{ static_url('topic/aqiyi_test/img/rwhr.png') }}", "{{ static_url('topic/aqiyi_test/img/logo.png') }}", ]; let len = imgs.length; /** * 遍历imgs数组,将所有图片加载出来 * 可以通过控制台查看网络请求,会发现所有图片均已加载 */ for (let i = 0; i < len; i++) { let imgObj = new Image(); // 创建图片对象 imgObj.src = imgs[i]; imgObj.addEventListener('load', function () { // 这里没有考虑error,实际上要考虑 console.log('imgs' + i + '加载完毕'); }, false); }