【发布时间】:2020-05-07 10:50:33
【问题描述】:
尝试在使用 CSS 的运行动画中使用 :hover 触发过渡,在下面的示例中,:hover 上只有 background-color 更改,但 transform 属性仅在动画停止后触发。如何在动画期间触发transform: rotate?
此外,当我重新加载页面时,我最初的background-color: red 似乎淡入了,而我没有通过:hover 明确触发它。我认为这是由transition-duration 引起的,仅使用 CSS 可以避免这种情况吗?
.container {
height: 300px;
display: flex;
justify-content: center;
align-items: center;
}
.red {
width: 100px;
height: 100px;
background-color: red;
animation-name: animation;
animation-duration: 5s;
animation-delay: 0;
animation-timing-function: ease-in-out;
animation-direction: alternate;
transition-duration: 5s;
transition-property: all;
}
.red:hover {
transform: rotate(180deg);
background-color: teal;
}
@keyframes animation {
0% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1);
}
}
<body>
<div class="container">
<div class="red"></div>
</div>
</body>
【问题讨论】:
标签: html css css-animations css-transitions