【发布时间】:2017-02-26 07:09:26
【问题描述】:
我的转换属性有问题。有一个带有position: absolute 的框。为了把它放在父 div 的中心,我使用transform: translate(-50%, -50%),因为在实际项目中我有自适应页面。所以,我不能使用 px 和负边距。
此外,我想应用 zoomIn 动画并看到动画线 transform: translate(-50%, -50%) 不起作用。我想,这是因为双重变换属性。
我该如何解决?
这是 Codepen 上的示例https://codepen.io/pndparade/pen/VKGXPj
html,
body{
height: 100%;
margin: 0;
padding: 0;
}
.box{
height: 100%;
width: 100%;
background: red;
position: relative;
}
.box-in{
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: #fff;
animation-duration: 1.5s;
animation-delay: 0.8s;
animation-fill-mode: both;
animation-name: zoomIn;
animation-iteration-count: infinite;
}
@keyframes zoomIn {
from {
opacity: 0;
-webkit-transform: scale3d(.3, .3, .3);
transform: scale3d(.3, .3, .3);
}
50% {
opacity: 1;
}
to {
-webkit-transform: scale3d(1, 1, .1);
transform: scale3d(1, 1, 1);
}
}
【问题讨论】:
标签: css animation css-transforms