我尝试像灯箱一样缩放图像。运行时图像的大小发生了变化,但没有动画。
<div id="dnn_ctr428_ContentPane" class="img-rectangular"><div id="dnn_ctr428_ModuleContent" class="DNNModuleContent ModDNNHTMLC">
<div id="dnn_ctr428_HtmlModule_lblContent" class="Normal">
<img alt="" src="/dnn_test/portals/0/Images/logo2.png?ver=1394-08-24-081741-293">
</div>
</div></div>
CSS:
.img-rectangular:hover img {
width: 120%;
height: 120%;
-webkit-transition: width 2000ms ease-in-out;
-moz-transition: width 2000ms ease-in-out;
-ms-transition: width 2000ms ease-in-out;
-o-transition: width 2000ms ease-in-out;
transition: width 2000ms ease-in-out;
}
原文由 hmahdavi 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您想在将鼠标悬停在容器上时缩放图像并且它必须通过
animation
那么您可以使用带有transform: scale()
的动画,就像下面的代码片段一样。与
width
和height
相比,使用scale()
转换的优势在于它 实际上并不需要设置初始高度和宽度。但是,
animation
并不是真正需要的,它也可以通过transition
来完成。使用transition
而不是animation
的优势在于,默认情况下,过渡会在悬停时产生反向(缩小)效果,而动画则需要不同的关键帧设置才能实现。