javascript代码:
<script type="text/javascript">
var FitWidth = 124;
var FitHeight = 85;
function ResizePic(ImgTag)
{
var image = new Image();
image.src = ImgTag.src;
if(image.width>0 && image.height>0){
if(image.width/image.height >= FitWidth/FitHeight){
if(image.width > FitWidth){
ImgTag.width = FitWidth;
ImgTag.height = (image.height*FitWidth)/image.width;
ImgTag.style.marginTop = (FitHeight-ImgTag.height)/2+"px";
}
else{
ImgTag.width = image.width;
ImgTag.height = image.height;
}
}
else{
if(image.height > FitHeight){
ImgTag.height = FitHeight;
ImgTag.width = (image.width*FitHeight)/image.height;
}
else{
ImgTag.width = image.width;
ImgTag.height = image.height;
}
}
}
}
//-->
</script>
图片代码,onload时间中调用javascript中的ResizePic函数
<img src="" style="margin:0px auto;" onload="javascript:ResizePic(this)" border="0" />
本文介绍了一种使用JavaScript实现图片自适应调整的技术,确保图片在不同设备上都能保持良好的视觉效果。
1万+

被折叠的 条评论
为什么被折叠?



