欢迎光临
我们一直在努力

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="http://hiphotos.baidu.com/中国旅游名县/pic/item/56d16e00e83803a6e850cdb2.jpg" width="400" height="300" border="0" /></div>
窗外天空
关注公众号『窗外天空』

获取更多建站运营运维新知!
互联网创业、前沿技术......

赞(0) 打赏
文章名称:《JS缩略图自动缩放显示》
文章链接:https://www.nixonli.com/22513.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

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

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

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏