欢迎光临
我们一直在努力

JS缩略图自动缩放显示

<script type="text/javascript">
function Zoom(obj, width, height){
 var img = new Image();
 img.src = obj.src;
 var scale = Math.max(width / img.width, height / img.height);
 var newWidth = img.width * scale;
 var newHeight = img.height * scale;
 var div = obj.parentNode;
 
 obj.width = newWidth;
 obj.height = newHeight;
 div.style.width = width + "px";
 div.style.height = height + "px";
 div.style.overflow = "hidden";
 obj.style.marginLeft = (width - newWidth) / 2 + "px";
 obj.style.marginTop = (height - newHeight) / 2 + "px";
}
</script>
<div><img src="https://hiphotos.baidu.com/中国旅游名县/pic/item/56d16e00e83803a6e850cdb2.jpg" width="400" height="300" border="0" /></div>
赞(0) 打赏
未经允许不得转载:NixonLi博客 » JS缩略图自动缩放显示

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏