[英]Serving Different Size Images For Different Devices Based On Resolution Using JavaScript
[英]Is there any way to resize the images based on screen resolution with out using javascript?
我打算在我的网站(976X450)中使用大横幅图像。现在在高分辨率显示器中,图像应拉伸以占据空间。 有没有办法使用不同分辨率的不同图像来做到这一点?
从检测屏幕尺寸开始,然后继续:
var width = screen.width;
var height = screen.height;
var img = document.getElementById(image_id);
img.height = img.height * width / img.width;
img.width = width;
更新 :
使用CSS:
img#in_question { width: 100% }
#HeaderImage {
height: 20%;
width: 100%;
background-repeat:repeat-x;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.