【发布时间】:2018-06-18 16:26:13
【问题描述】:
我想让这张卡片在悬停时缩放(包括其中的元素),但是在转换过程中(当您悬停卡片时)文本会摇晃/抖动,并且在缩放期间和之后变得模糊(有时,有一些比例比其他人多,我认为这是由于亚像素值四舍五入)。
如何消除转换过程中的摇晃和模糊?
-
我不关心 IE 浏览器,我只希望它在最新的 Chrome 中工作。
-
好像是
transition属性引起的。
Codepen #1: https://codepen.io/x84733/pen/yEpYxX
.scalable {
transition: 0.3s ease-in-out;
box-shadow: 0 6px 10px rgba(0,0,0,0.14);
}
.scalable:hover {
transform: scale(1.05);
box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}
.card {
width: 100%;
background: white;
padding: 20px;
}
body {
width: 50%;
height: 100%;
background: #999;
padding: 20px;
}
<div class="card scalable">
<div>here's some description</div>
</div>
更新:
我刚刚发现,当您以编程方式对其进行动画处理时,它不会摇晃/抖动:
我可以在 JS 中以某种方式使用它吗?
Codepen: https://codepen.io/anon/pen/LqXwOb?editors=1100
.anim {
animation: scale 0.3s ease-in-out infinite alternate;
}
@keyframes scale {
to { transform: scale(1.05) }
}
.scalable {
transition: 0.3s ease-in-out;
box-shadow: 0 6px 10px rgba(0,0,0,0.14);
}
.scalable:hover {
transform: scale(1.05);
box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}
.card {
width: 100%;
background: white;
padding: 20px;
}
body {
width: 50%;
height: 100%;
background: #999;
padding: 20px;
}
<div class="el anim card scalable">
<div>here's some description</div>
</div>
【问题讨论】:
-
我不知道是什么原因造成的。您是否尝试过设置 backface-visibility: hidden,这对我有用。
-
@Countingstuff 刚刚尝试将此规则添加到指定的代码笔中,但仍然不起作用。文字在转换过程中变得模糊和摇摆
-
@Countingstuff 有正确的答案。添加 backface-visibility: hidden 在类和悬停解决它!
-
@AdrianDanlos 它没有,它在转换过程中仍然摇晃,并且在缩放后变得模糊,请参阅此代码笔:codepen.io/anon/pen/aXRdXV
-
你说得对-_-
标签: css scale css-transforms