【问题标题】:preload image with jquery of window onload使用窗口加载的jquery预加载图像
【发布时间】:2014-09-10 06:48:48
【问题描述】:

这是一个在window onload中的gif,如何用jquery预加载它?由于尺寸的原因,它有点滞后..

似乎我必须切换到 css 预加载器而不是 gif?

【问题讨论】:

  • 谷歌会帮你...
  • 目前有 5 人无法回答这个被否决的问题..

标签: javascript jquery css


【解决方案1】:

您可以在 javascript 中的 window.onload 方法中预加载图像。之前隐藏它,使用 css 并在图像加载时(在 onload image 事件中)显示它。

 .hide { display: none; } 
 .show { display: block; } 

 var img = new Image();   // Create new img element
 img.src = 'myCoolGiff.gif'; 
 img.addEventListener("load", function() {   
   // execute drawImage    
   this.style.className = "show";  
 },false);

【讨论】:

    猜你喜欢
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 2012-05-17
    • 2011-08-25
    • 1970-01-01
    相关资源
    最近更新 更多