【问题标题】:How can I exclude some images from being preloaded如何从预加载中排除某些图像
【发布时间】:2014-08-01 19:34:43
【问题描述】:

我真的找不到这个问题的答案。

我有一个网站的预加载器。网站上有一个包含 10mb 动画 gif 的幻灯片。

有没有办法从预加载中排除一些 gif,这样网站本身就不会等待在幻灯片开始时不会显示的 gif? 谢谢!

这是我的预加载器:

HTML:

<!-- Preloader -->
<div id="preloader">
 <div id="status">
   <div class="parent">
     <div class="child">
       <p class="small">loading</p>
     </div>
   </div>
 </div>

CSS:

#preloader { position:absolute; top:0; left:0; right:0; bottom:0; background:#000; z-index:9999; }
#status { z-index:28; position:absolute; color:#fff; top:50%; height:280px; width:100%; margin-top:-140px; }
/* horizontal centering */
.parent {width:280px; margin:0px auto; position:relative; height:280px; z-index:11}
.child {text-align:center;}
/* vertical centering */
.parent {display: table}
.child {display: table-cell; vertical-align: middle; padding:0 50px; }
.child span { text-transform:uppercase; }

preloader.js:

jQuery(window).load(function() { 
"use strict";
        jQuery("#status").fadeOut(350); // will first fade out the loading animation
        jQuery("#preloader").delay(350).fadeOut(200); // will fade out the white DIV that covers the website.
    });

编辑: 我在This website

找到了以下内容

我仍然不知道如何使用它。有什么提示吗?你会说这可能是我要找的吗?谢谢。

影响预加载器

目前我们可以通过有限的方式影响预加载器的优先级(使用 javascript 隐藏资源就是其中之一),但 W3C 资源优先级规范提出了两个属性来帮助表明我们的意图。

lazyload : 在其他未标记为lazyload 的资源开始下载之前,不应下载资源

postpone : 资源在用户可见之前不得下载,即在视口内且显示不是无。

虽然我不确定 polyfill 有多容易,但也许推迟可以实现一种实现响应式图像的简单方法?

【问题讨论】:

    标签: jquery css slideshow animated-gif preloader


    【解决方案1】:
    jQuery(window).load(function() { 
    "use strict";
        jQuery("#status").fadeOut(350); // will first fade out the loading animation
        jQuery("#preloader").delay(350).fadeOut(200); // will fade out the white DIV that     covers the website.
        $('.somewhere').append("/*your slide gif code here*/"); // this will load after everything else is loaded. and make sure you put your script right before closing </body> tag, so it will load everything on the page 1st. it will increase you page load. 
    });
    

    并删除您的幻灯片 IMG html,并将其移动到您的 .load 函数中。

    【讨论】:

    • 它卡在预加载...我应该之前发布更多信息。这就是我的 html
    • 再次(第一次使用这些 cmets!)HTML
      &lt;div class="element clearfix col2-3 home"&gt; &lt;div id="slideshow-container"&gt; &lt;div id="slideshow"&gt; &lt;div id="box1"&gt;&lt;img src="images/about04.jpg"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt;
    • JS:jQuery(window).load(function() { "use strict"; jQuery("#status").fadeOut(350); // will first fade out the loading animation jQuery("#preloader").delay(350).fadeOut(200); // will fade out the white DIV that covers the website. $(".slideshow").append("&lt;div id="box1"&gt;&lt;img src="images/organix.gif"&gt;); $(".slideshow").append(&lt;div id="box1"&gt;&lt;img src="images/house.gif"&gt;); });
    • 你是这个意思吗?
    • 我在我的回答中添加了评论,如果您将脚本放在
    【解决方案2】:

    我最终使用了Cycle2 它会逐步加载图像。

    我认识的一个程序员写了这个:

    "你需要在你的 html 文件中使用 "cycle-slideshow" 类来调整 div-Block 并将以下属性添加到标签:

      data-cycle-loader=true
      data-cycle-progressive="#slideshow-images"
    

    您的 div-Tag 现在应该只包含一张图片,即第一张。所有其他图像 去名单上。 “slideshow-images”是一个 id(由它前面的 # 表示) 的列表,您在其中列出您希望幻灯片显示和加载的所有图像 逐步。它具有以下形式:

      <script id="slideshow-images" type="text/cycle">
      [
        "<img src='http://malsup.github.io/images/beach2.jpg'>",
        "<img src='http://malsup.github.io/images/beach3.jpg'>",
        ...
        "<img src='http://malsup.github.io/images/beach9.jpg'>"
      ]
      </script>"
    

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签