我正在尝试使用 CSS3 Transform(缩放)为容器创建放大功能,并且一切似乎都运行良好,但是当缩放图像时,溢出仅覆盖图像的一部分,而将左上角部分排除在外溢出。
代码如下:
HTML:
<div class="outer">
<img id="profile" src="http://flickholdr.com/300/200/" />
</div>
<button class="zoom orig">Original</button>
<button class="zoom x2">x2</button>
<button class="zoom x4">x4</button>
CSS:
.outer { width: 500px; height: 500px; overflow: auto; text-align: center; background: #eee; }
.outer:before { content: ''; display: inline-block; vertical-align: middle; height: 100%; }
.outer img { vertical-align: middle; }
.scale_x2 { -webkit-transform: scale(2); -moz-transform: scale(2); -ms-transform: scale(2); -o-transform: scale(2); transform: scale(2); }
.scale_x4 { -webkit-transform: scale(4); -moz-transform: scale(4); -ms-transform: scale(4); -o-transform: scale(4); transform: scale(4); }
JS:
$(function() {
$('.zoom').on("click", function() {
if ($(this).hasClass('orig')) {
$("#profile").removeClass();
} else if ($(this).hasClass('x2')) {
$("#profile").removeClass().addClass('scale_x2');
} else if ($(this).hasClass('x4')) {
$("#profile").removeClass().addClass('scale_x4');
}
});
});
检查这里的小提琴:http://jsfiddle.net/sbaydakov/RhmxV/2/ http://jsfiddle.net/sbaydakov/RhmxV/2/
关于如何完成这项工作,以便可以查看整个图像,有什么想法吗?
Thanks.
图像从中心径向向外缩放,从而导致左上角图像像素消失。检查这个工作小提琴http://jsfiddle.net/RhmxV/37/ http://jsfiddle.net/RhmxV/37/
.scale_x2 {
margin-left: 150px;
margin-top: -193px;
-webkit-transform: scale(2);
-moz-transform: scale(2);
-ms-transform: scale(2);
-o-transform: scale(2);
transform: scale(2);
}
.scale_x4 {
margin-left: 450px;
margin-top: 15px;
-webkit-transform: scale(4);
-moz-transform: scale(4);
-ms-transform: scale(4);
-o-transform: scale(4);
transform: scale(4);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)