87,997
社区成员




.divcss img
{
max-width: 250px; /*这是DIV的大小*/
width: expression(this.width > 80 ? "80px" : this.width); /*实现按比例缩放*/
max-height: 230px;
height: expression(this.height > 80 ? "80px" : this.height); /*实现按比例缩放*/
}
这样整个div下的图片就都按比例缩放了/*设备小于680,设置新闻详细中图片宽度100%,高度auto等比缩放*/@media screen and (max-width:680px){
#newbody img{width:100% !important;height:auto !important;}
}
/*更多的query选择移动端分辨率样式*/
通过@media screen控制网站在移动端显示
var img = document.getElementById('imgid');
img.style.width = "100%"
img.style.height = "auto"
<html>
<head>
<meta charset = "utf-8">
</head>
<body>
<img id = 'imgid' src = "1.jpg" >
<script>
//如果图片过大,处理图片大小。使用要求:传递id和大小要求。示例:autoImgSize('img1',1000)
function autoImgSize(img,size){
if(!size){
size=1000;//设置默认最大值为1000
}
var imgobj= document.getElementById(img); //获取对象
imgobj.style.width = "auto";
imgobj.style.height = "auto"; //释放图片本来的大小
var imgwidth=imgobj.width;
var imgheight=imgobj.height;
if(imgwidth>imgheight){ //判断是width和height哪一个大。大的先处理。设置最大值size
if(imgwidth>size){
imgobj.style.width = size + "px";
}
imgheight=imgobj.height;
if(imgheight>size){
imgobj.style.height = size + "px";
}
}else{
if(imgheight>size){
imgobj.style.height = size + "px";
}
imgwidth=imgobj.width;
if(imgwidth>size){
imgobj.style.width = size + "px";
}
}
}
window.onload = function(){
autoImgSize('imgid',500);
}
</script>
</body>
传入屏幕宽度就可以适应缩放了。