简体   繁体   English

隐藏图像时是否下载了图像?

[英]Are images downloaded when they are hidden?

I am using the jQuery plugin FancyBox from: http://fancybox.net/ and I'm basically using it for a "hidden gallery"; 我使用的是来自http://fancybox.net/的jQuery插件FancyBox ,基本上是将其用于“隐藏的画廊”; meaning the images aren't displayed on the page at all, the gallery is launched via a text link and then the user can scan through them once opened. 这意味着图像根本不会显示在页面上,画廊通过文本链接启动,然后用户可以在打开图像时对其进行扫描。

To achieve this I am doing something like this: 为了实现这一点,我正在做这样的事情:

<div class="all_images">
    <a href="images/1.png" class="gallery" rel="g1"></a>
    <a href="images/2.png" class="gallery" rel="g1"></a>
    <a href="images/3.png" class="gallery" rel="g1"></a>
</div>

Then in CSS I do: 然后在CSS中执行:

.all_images {
    display: none;
}

Now I'm wondering if the images are downloaded like this because they are hidden or does it vary by browser? 现在,我想知道是否由于隐藏了图像而像这样下载图像,或者图像是否因浏览器而异?

I'd probably prefer it if they didn't as some images may be large and I don't want the user downloading a bunch of images if they don't wish to view them. 如果它们没有,我可能会更喜欢,因为某些图像可能很大,如果用户不希望查看它们,我不希望用户下载大量图像。

In your example you are not displaying <img/> elements. 在您的示例中,您没有显示<img/>元素。 You only have hyperlinks that will link to the image if clicked. 如果单击,只有链接将链接到图像的超链接。 There will be no downloading. 将没有下载。

If they were <img/> tags, they would be downloaded even if they were set to display:none 如果它们是<img/>标签,即使将它们设置为display:none ,也将下载它们display:none

If you are looking to optimize the page by removing unnecessary downloads of images. 如果您要通过删除不必要的图像下载来优化页面。 You could combine all of those images in to one big image and load this image as a background-image; 您可以将所有这些图像合并为一个大图像,并将该图像作为背景图像加载; You can then leverage the CSS background-position; 然后,您可以利用CSS的背景位置; property to use the piece of image under each item(div, a, li et-al). 属性以使用每个项目(div,a,li等)下的图片。 This way you will be making just one http request to load all the images, which is good page optimization technique and avoiding unnecessary http requests. 这样,您将只发出一个http请求来加载所有图像,这是一种很好的页面优化技术,可以避免不必要的http请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM