【发布时间】:2014-04-01 11:18:25
【问题描述】:
我正在 JavaScript 中制作一些函数,用于使用变换比例进行放大和缩小。这些功能工作得很好。问题是缩放后的图像在缩小时向下移动,在放大时向上移动。我想将它保持在 div 的中心。
HTML:
<div class="skew"><img id="blah" align="middle" style="margin:0 auto 0 auto;"src="http://3rdbillion.net/wp-content/uploads/2013/11/a24cc9de0c523a5bf7680e18af1952853.jpg"/></div>
<div id="zoom">
<button type="button" value="zoom in" id="in" onclick="zoomin()" style=" width:80px;height: 25px;">Zoom In</button><br>
<button type="button" value="zoom out" onclick="zoomout()" id="out"style="height: 25px;" >Zoom Out</button>
</div>
CSS:
.skew {
display: inline-block;
height: 120px;
width: 360px;
margin-top: 100px;
overflow: hidden;
}
JS:
function zoomin()
{
document.getElementById('blah').style.transform = "scale(2,2)";
document.getElementById('blah').style.webkitTransform = "scale(2,2) ";
document.getElementById('blah').style.msTransform = "scale(2,2)";
}
function zoomout()
{
document.getElementById('blah').style.transform = "scale(0.5,0.5) ";
document.getElementById('blah').style.webkitTransform = "scale(0.5,0.5)";
document.getElementById('blah').style.msTransform = "scale(0.5,0.5)";
}
【问题讨论】:
-
你能给我们看一些代码吗?
-
这里是小提琴jsfiddle.net/9M7gV/3 出于某种原因它不起作用,但我认为它会帮助您了解我的问题是什么
标签: javascript html css