简体   繁体   English

图像是否已加载并保持隐藏状态,或者不是在隐藏的div中加载了?

[英]Are images loaded and remain hidden or aren't they loaded in hidden div?

In mobile sites, I am hiding the slideshow by using: 在移动网站中,我使用以下方法隐藏幻灯片:

#slideshow{ display: none}

Do the image load and remain hidden or they do not load? 图像加载并保持隐藏还是不加载? Should I use server side PHP to avoid loading the image sources? 我应该使用服务器端PHP来避免加载图像源吗? If they load, what can I do to browse faster and to avoid more data streaming in Mobile devices? 如果它们加载,我该怎么做才能更快地浏览并避免在移动设备中流式传输更多数据?

Any comments and suggestions will be highly appreciated. 任何意见和建议将不胜感激。 I DO NOT want the site to look better in Mobile, I am aiming at making code perfect.... 我不希望该网站在Mobile中看起来更好,我的目标是使代码完美。

I think this depends on the Browser that defines to load/ not to load the images. 我认为这取决于定义加载/不加载图像的浏览器。 Most modern browsers do so as to give better browsers experience. 大多数现代浏览器都这样做,以提供更好的浏览器体验。 So as far as speed, images are loaded async. 因此,就速度而言,图像会异步加载。 So, it rarely matters. 因此,这无关紧要。 But, As per data, If I were you, I would change in the PHP Script and get rid of it as you are concerned with better Web Structure. 但是,根据数据,如果您是我,我将更改PHP脚本并摆脱它,因为您担心更好的Web结构。 It may need a lot of effort, but it's better than Javascript which sometimes load after images. 它可能需要很多努力,但是比有时在图像后加载的Javascript更好。

This helps you to detect a mobile device in PHP: Simplest way to detect a mobile device 这可以帮助您检测PHP中的移动设备: 检测移动设备的最简单方法

To answer your questions: 要回答您的问题:

Images load in MOST browsers. 图像会加载到MOST浏览器中。 NOT ALL. 并非全部。 In order to test, try this page with your browser and see the results: 为了进行测试,请在浏览器中尝试此页面并查看结果:

Display IMG test 显示IMG测试

What to do to avoid that: Besides the jQuery approaches, one common method in responsive design is to use DATA URI , like this: 为避免这种情况该怎么做:除了jQuery方法,响应式设计中的一种常见方法是使用DATA URI ,如下所示:

data:[<mime type>][;charset=<charset>][;base64],<encoded data>

This has the advantage that you use less requests AND doesn't download unless it's on a visible element, so it's a win win situation 这样的好处是您使用的请求更少,并且除非它位于可见元素上,否则不会下载,因此这是双赢的局面

yes when you use #slideshow{ display: none} slideshow images loaded at mobile phone 是,当您使用#slideshow{ display: none}在手机上加载的幻灯片图像时

yo avoid that in slideshow i suggest you use like: 哟避免在幻灯片放映中使用,我建议您像这样使用:

   $(document).ready(function(){
    if ($(window).width() < 960) {
       $("#slideshow").remove( );
    }
});

How about removing the content using jQuery like: 如何使用jQuery删除内容:

$("#slideshow").html("");

This makes the content nothing. 这使得内容一无所有。 But I am not sure if that does not stream. 但是我不确定这是否会流。 Since Javascript DOM is Dynamic, I think that must work. 由于Javascript DOM是动态的,因此我认为这必须可行。 You can load high images and test the data used in browsing. 您可以加载高图像并测试浏览中使用的数据。

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

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