CSS3变换缩放和容器与溢出 [英] CSS3 Transform Scale and Container with Overflow
问题描述
我想为一个容器使用CSS3 Transform(scale)创建一个放大功能,并且似乎都很好地工作,但是当图像缩放时,溢出只覆盖图像的一部分,留下左上角
代码如下:
HTML:
< div class =outer>
< img id =profilesrc =http://flickholdr.com/300/200//>
< / div>
< button class =zoom orig>原始< / button>
< button class =zoom x2> x2< / button>
< button class =zoom x4> x4< / button>
CSS:
code> .outer {width:500px; height:500px; overflow:auto; text-align:center;背景:#eee; }
.outer:before {content:''; display:inline-block; vertical-align:middle;高度: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 )){
$(#profile)。removeClass();
} else if($(this).hasClass('x2')){
$(#profile ).removeClass()。addClass('scale_x2');
} else if($(this).hasClass('x4')){
$(#profile)。 addClass('scale_x4');
}
});
});
在这里检查一下: http://jsfiddle.net/sbaydakov/RhmxV/2/
有关如何制作此内容的任何想法
p>图像从中心径向向外缩放,从而导致左上图像像素消失。检查此工作无效的 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);
}
I am trying to create a zoom-in functionality for a container with CSS3 Transform (scale) and all seems to work nicely, but when the image is scaled, the overflow only covers a part of the image, leaving the top left part out of the overflow.
Code is as follows:
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');
}
});
});
Check the fiddle here: http://jsfiddle.net/sbaydakov/RhmxV/2/
Any thoughts on how to make this work, so that the whole image is viewable?
Thanks.
The image is scaled from center radially outwards, thus causing the top-left image pixels to disappear. Check this working fiddle 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);
}
这篇关于CSS3变换缩放和容器与溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!