gpt4 book ai didi

html - 不同属性的 CSS3 不同自定义缓动

转载 作者:太空宇宙 更新时间:2023-11-04 03:26:19 24 4
gpt4 key购买 nike

我已经为某个 div 设置了动画。

.Animation
{
-webkit-animation-fill-mode: both; /*and also -moz, -ms etc. */
animation-fill-mode: both;
-webkit-animation-delay: 1s;
animation-delay: 1s;
-webkit-animation-duration: 2s;
animation-duration: 2s;
}

@-webkit-keyframes scaleAnimation /*and also -moz, -ms etc. */
{
0%
{
opacity: 0;
-webkit-transform: scale(2);
}

100%
{
opacity: 1;
-webkit-transform: scale(1);
}
}

.ScaleAnimation
{
-webkit-animation-name: scaleAnimation; /*and also -moz, -ms etc. */
animation-name: scaleAnimation;
}

但我想要一个不同的自定义缓动(立方贝塞尔曲线)用于不透明度和另一个自定义缓动用于变换。我该如何让它发挥作用。

以下无效:

transition: opacity 1s ease-in-out;
transition: scale 1s ease-in-out;

所以它肯定不适用于自定义缓动,cubic-bezier(0.555, -0.130, 0.270, 1.075);例如。

有什么想法吗? :)

最佳答案

对于转换,您可以通过逗号分隔来指定多个转换。

transition: <duration> <property> <delay> <timing-function>, ....
transition: 1s opacity 1s ease-in-out, 1s scale 1s linear;

如果您想走动画/关键帧路线,那么您可以创建两个动画关键帧。一个用于缩放,另一个用于不透明度。然后在元素的动画设置中用逗号分隔它们。

缓动的属性是animation-timing-function。对于基于 webkit 的浏览器(从您的问题看来,您不介意供应商前缀),它变为 -webkit-animation-timing-function

您可以像这样设置它:

div {
width: 120px; height: 120px;
background-color: red;
display: inline-block;
}

div.d1 {
-webkit-animation-fill-mode: both;
-webkit-animation-delay: 2s, 2s;
-webkit-animation-duration: 2s, 2s;
-webkit-animation-name: scaleAnimation, opacityAnimation;
-webkit-animation-timing-function:
cubic-bezier(0.1, 0.7, 1.0, 0.1), ease-in;
}

div.d2 {
-webkit-animation-fill-mode: both;
-webkit-animation-delay: 2s, 2s;
-webkit-animation-duration: 2s, 2s;
-webkit-animation-name: scaleAnimation, opacityAnimation;
-webkit-animation-timing-function: linear linear;
}

@-webkit-keyframes scaleAnimation {
0% {
-webkit-transform: scale(2);
}
100% {
-webkit-transform: scale(1);
}
}

@-webkit-keyframes opacityAnimation {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="d1">D1</div>
<div class="d2">D2</div>

fiddle :http://jsfiddle.net/abhitalks/3y7pcd1t/1/

.

关于html - 不同属性的 CSS3 不同自定义缓动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27039565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com