简体   繁体   English

转换比例会破坏滚动条?

[英]Transforming scale ruins the scrollbars?

In CSS, we can do a nice scale effect on images, without hassling too much with their width and height attribute:在 CSS 中,我们可以对图像进行很好的缩放效果,而无需过多地使用它们的宽度高度属性:

transform: scale(2);

To reach a common goal, it's better to adjust the origin too:为了达到共同的目标,最好也调整原点

transform-origin: center;

This way the image will be scaled while keeping its origin at the center, so it will be more natural to the human eye.这样,图像将在保持原点位于中心的同时进行缩放,因此对人眼来说会更自然。

However, if we put this image (and why shouldn't we do) into a wrapper, this seems ruining the scrollbars.但是,如果我们将这个图像(以及为什么我们不应该这样做)放入一个包装器中,这似乎会破坏滚动条。

Consider this image:考虑这张图片:

在此处输入图像描述

This is a fairly big image, and I put it into a fixed sized wrapper.这是一个相当大的图像,我将它放入一个固定大小的包装器中。

After applying also the scaling CSS, scrollbars are ruined, ie I can't move upwards nor left, so the left and top parts of the image are cut, while we can move downwards and right without issues.在应用缩放 CSS 之后,滚动条被破坏了,即我不能向上或向左移动,所以图像的左侧和顶部被剪切,而我们可以向下和向右移动而没有问题。

Here is the very simple JSFiddle: http://jsfiddle.net/thyzog8u/这是非常简单的 JSFiddle: http://jsfiddle.net/thyzog8u/

Can I somehow easily overcome on this limitation of using scale with CSS?我能否以某种方式轻松克服在 CSS 中使用scale的限制?

在此处输入图像描述

 .image_wrap { width:400px; height:200px; overflow:auto; }.image_wrap img { transform: scale(2); transform-origin: center; }
 <div class="image_wrap"> <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_1.jpg" alt="" /> </div>

scale and transform in general doesn't affect the layout flow. scaletransform一般不会影响布局流程。 You have to use width and height properties for this:您必须为此使用widthheight属性:

 .image_wrap { width:400px; height:200px; overflow:auto; }.image_wrap img { width: 1360px; /* 680 (image width) * 2 */ height: 640px; /* 320 (image height) * 2 */ }
 <div class="image_wrap"> <img src="http://www.alessioatzeni.com/CSS3-Cycle-Image-Slider/images/img_1.jpg" alt="" /> </div>

You can also use Javascript to get a dynamic image size.您还可以使用 Javascript 来获取动态图像大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM