[英]CSS keyframes - Scale and translate
I'm trying to scale and translate an absolute positioned div
, but after the scale, the div
won't move to the exact coordinates I gave it in my keyframe. 我正在尝试缩放和转换绝对位置的
div
,但是缩放后, div
不会移动到我在关键帧中给定的确切坐标。
I know it's due to the coordinates of the div
, which remains the same as when unscaled. 我知道这是由于
div
的坐标所致,它与未缩放时的坐标相同。
I could just adjust the final coordinates of my keyframe, but is there a smarter way to fix that? 我可以调整关键帧的最终坐标,但是有更聪明的方法来解决这个问题吗?
Here's my code (vendor prefixes removed voluntarily), and here's a fiddle . 这是我的代码(自愿删除供应商前缀), 这是一个小提琴 。
<div class="popin willGoToUpperLeft"></div>
.popin{
width:400px;
height:200px;
position:absolute;
top:300px;
left:200px;
background:url('//placekitten.com/400/200');
}
.willGoToUpperLeft{
animation: scaleOut 1s ease-in-out 0s 1 normal forwards,
goToLeftCorner 1s ease-in-out 1s 1 normal forwards;
}
@keyframes scaleOut {
0% {
transform: scale(1);
}
100% {
transform: scale(0.1);
}
}
@keyframes goToLeftCorner {
100% {
top: 0px;
left: 0px;
}
}
Ended up using 最终使用
transform-origin: 0% 0%;
to keep the original coordinates. 保持原始坐标。
It's a workaround, the effect isn't as awesome as scaled from center, but that will work for now. 这是一种解决方法,效果不如从中心缩放那么好,但是暂时可以使用。
If someone has a smart solution to keep scaling from center, I'm interested! 如果有人有一个聪明的解决方案来保持从中心扩展,我很感兴趣!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.