简体   繁体   English

是否在容器内添加了“ display:none”的“延迟加载”图像?

[英]“Lazy load” images that are inside containers with “display:none” added to them?

I am a lil confused how lazy load for images work in general and would like to understand better. 我有点困惑,一般来说,图像的延迟加载是如何工作的,我想更好地理解。

I am using this simple php plugin to lazy load image on my website. 我正在使用这个简单的PHP插件在我的网站上延迟加载图像。 https://github.com/Jumedeenkhan/lazy-load-for-images (js at bottom of php file) https://github.com/Jumedeenkhan/lazy-load-for-images(php文件底部的js)

I know that it will "Lazy load" images that are "below the fold". 我知道它将“延迟加载”“未折叠”的图像。 However I was wondering does it also lazy load an image if the image or the images container is set to "display:none" or is "hidden". 但是我想知道,如果图像或图像容器设置为“ display:none”或“ hidden”,它是否也会延迟加载图像。

For example I have a set of "Tabs" and each tab has products inside. 例如,我有一组“标签”,每个标签内都有产品。 The default tab of course shows the images - but the other tabs have content with images also that are not displayed until the person clicks the corresponding tab. 默认选项卡当然会显示图像-但其他选项卡也包含图像内容,直到用户单击相应的选项卡时才会显示。 So my question is does this "plugin" solution above also "Lazy load" images in the scenario of "tabs" described above? 因此,我的问题是,在上述“选项卡”方案中,上面的“插件”解决方案是否还会“延迟加载”图像?

If not - is there a better solution i should be trying to solve that issue? 如果不是-是否有更好的解决方案,我应该尝试解决该问题?

Thanks for any insight! 感谢您的任何见解!

edit - im adding JS back to the tags since the php file is loading js script at the bottom of it. 编辑-由于php文件正在底部加载js脚本,因此我将JS添加回了标签。 Which i think is the core of the lazy loading function 我认为这是延迟加载功能的核心

From line 82 on in that code you have this code 从该代码的第82行开始,您拥有此代码

return '<img ' . $matches['before']
    . ' class="lazy ' . $matches['class1'] . $matches['class2'] . '" src="' . $placeholder_image . '" '
    . $matches['between1'] . $matches['between2']
    . ' data-src="' . $matches['src1'] . $matches['src2'] . '" '
    . $matches['after']
    . $matches['closing'] . '><noscript>' . $matches['all'] . '</noscript>';

You will get HTML like this: The braces [] denote code that is inserted at that place but which is irrelevant to this question. 您将获得如下HTML:花括号[]表示插入该位置的代码,但与该问题无关。

<img [] class="lazy []' src="/path/to/some-placeholder-image.ext" [] data-src="path/to/original-image-to-be-lazy-loaded.ext" []><noscript>[]</noscript>

You see that the image is represented as data-src and not as src . 您会看到该图像表示为data-src而不是src

So, yes, this is a suitable lazy-loading script 所以,是的,这是一个合适的延迟加载脚本

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

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