62,067
社区成员
发帖
与我相关
我的任务
分享
<img id="imgPro" runat="server" class="imgInfo" />
.imgInfo
{
max-width:365px;
width:expression(document.body.clientWidth>365?"365px":"auto");
overflow:hidden;
}
this.imgPro.Attributes.Add("onload", "changeImg(this)");//有时可以控制,有时图片就原样显示,必须刷新几次才行
<script language="javascript" type="text/javascript">
<!--
function changeImg(mypic){
var xw=365;
var width = mypic.width;
var height = mypic.height;
var bili = width/height;
var A=width/xw;
if(A>1)
{
mypic.width=xw;
mypic.height=xw/bili;
}
}
//-->
</script>
this.imgPro.Attributes.Add("onload", "javascript:if (this.width>365) this.width=365;");
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 102; //定义允许图片宽度,当宽度大于这个值时等比例缩小
var iheight = 80; //定义允许图片高度,当宽度大于这个值时等比例缩小
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
//
//-->
</script>
"<a href='ImageView.aspx?IMG=uploads/"+names[i]+"' target='_blank'><img src='uploads/"+names[i]+"'onload='javascript:if(this.width>screen.width-320)this.width=screen.width-320' border=0 alt='点击放大看原图'></a><br>";
}
<img src="1.jpg" onload="if(this.width>356)this.width=365" alt="#" />
function ImgW(ImgID,Width){
var obj = document.getElementById(ImgID);
if(obj != null)
{
var w = obj.width;
var h = obj.height;
if (w > Width){
obj.width = Width;
obj.height = h*Width/w;
}
}
};
window.onload=function()
{
ImgW("图片的id" ,"365");
}