HTML控制图片居中缩放

<html>
<head>
</head>
<body>
<div style="display:table;text-align:center;width:100%;height:100%;" onmousewheel="bbimg();">
	<span style="display:table-cell;vertical-align:middle;">
	<img id="img1" src="https://www.baidu.com/img/baidu_jgylogo3.gif" />
	</span>
</div>

<script type="text/javascript">
function bbimg(){
	var img=document.getElementById("img1");
	var zoom=parseInt(img.style.zoom, 10) || 100;
	zoom+=event.wheelDelta/12*3;
	
	if(zoom>0) img.style.zoom=zoom+'%';
}
</script>
</body>
</html>

  

posted on 2022-07-27 00:18  PER10  阅读(328)  评论(0编辑  收藏  举报

导航