简体   繁体   English

网站中不同尺寸的图像取决于屏幕分辨率

[英]Different size images in website depending on screen resolution

I have a website with some images, and for this the page loading can be slow on mobile devices that have only mobile internet connection. 我的网站上有一些图片,为此,在只有移动互联网连接的移动设备上,页面加载速度可能很慢。 So, my question is: assign different images, smaller or bigger depending on device, when page is loaded could be a solution? 因此,我的问题是:在页面加载时,根据设备分配不同的图像(更大或更小)可能是一种解决方案?

Example Initially my img in the dom could be: 示例最初,我在dom中的img可能是:

<img src="" id="img1" alt="img1" />

And then, adding a script in head: 然后,在头中添加一个脚本:

$(document).ready(function () {
               loadImg();
            })

The loadImg function can be like: loadImg函数可以像:

if((window.screen.availHeight < 1234)&&(window.screen.availWidth < 1234))
document.getElementById("img1").src = "small";
else
document.getElementById("img1").src = "big";

Try this js library https://github.com/scottjehl/picturefill 试试这个js库https://github.com/scottjehl/picturefill

I don't know how this affects the SEO, though. 我不知道这如何影响SEO。

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

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