在 CC 之前预加载图像 - per souders

发布于 2024-09-14 20:31:06 字数 415 浏览 4 评论 0原文

我看到了 steve souders 的 PPT,内容是关于在 css 之前加载图像,以适应我需要的类似情况……但我不清楚执行此操作的实际代码是什么。我假设他在 css 之前加载了一些东西,并且在他的 ppt 中说了这一点

new Image().src = "http://webcelerity.com/blog/wp-content/themes/carrington-blog-faster/images/sprite.png

,但如果有人可以向我展示文档头实际上是什么样子,那就太棒了

这里是 ppt,

提前感谢您的帮助

I saw a PPT from steve souders about loading images before the css for a similar situation that i need.... but im not clear on what the actual code is to do this. I assume he loaded something before the css and in his ppt he says this

new Image().src = "http://webcelerity.com/blog/wp-content/themes/carrington-blog-faster/images/sprite.png

but it would be awesome if someone can show me what the doc head would actually look like

for ref; here is the ppt

thanks for your help in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浴红衣 2024-09-21 20:31:06

预加载图片的方法已经存在很久了,第一次见到是在用Dreamweaver MX做翻转效果的时候。

使用该方法,您可以并行下载图像并将其缓存在浏览器中(无需在此时实际显示它们)。

关于你的问题,文件的标题看起来像:

<script type="text/javascript">
var images = ['img1.jpg', 'img2.jpg'];

for(var i = 0, len = images.length; i < len; i++) {
  new Image().src = images[i];
}
</script>
<link rel="stylesheet" type="text/css" href="your_css_file.css" />

The method of preloading images has been around for ages, first time I had seen it was when I used Dreamweaver MX to do rollover effects.

Using that method you can parallelize download of the images and cache them in the browser (without the need of actually displaying them at that moment).

Regarding your question, the head of the document would look something like:

<script type="text/javascript">
var images = ['img1.jpg', 'img2.jpg'];

for(var i = 0, len = images.length; i < len; i++) {
  new Image().src = images[i];
}
</script>
<link rel="stylesheet" type="text/css" href="your_css_file.css" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文