简体   繁体   English

CSS翻转动画不起作用

[英]CSS flipping animation not working

using CSS3 perspective, I would like to make a flipping animation. 使用CSS3透视图,我想制作一个翻转动画。 Here is my code: 这是我的代码:

HTML: HTML:

<header>
    <div id="h1">
        <h1>Title</h1>
    </div>
</header>

CSS: CSS:

header div#h1{
    width: 150px;
    perspective: 150px;
    -webkit-perspective:150px; 
}
header div#h1 h1{
    position: absolute;
    animation: flip 5s infinite;
}


@keyframes flip{
    0%{
        transform: rotate(0);
        -webkit-transform: rotate(0);
    }
    25%{
        transform: rotateX(45deg);
        -webkit-transform: rotateX(45deg);
    }
    50%{
        transform: rotateX(90deg);
        -webkit-transform: rotateX(120deg);
    }
    75%{
        transform: rotateX(120deg);
        -webkit-transform: rotateX(120deg);
    }
    100%{
        transform: rotateX(180);
        -webkit-transform: rotateX(180);
    }
}
/* -webkit- keyframes */

FIDDLE 小提琴

It seems like this animation should work, but it doesn't. 似乎该动画应该起作用,但事实并非如此。

Why is this not working? 为什么这不起作用?

Thank you. 谢谢。

I added some prefixes. 我添加了一些前缀。 Please check this fiddle. 请检查这个小提琴。

Fiddle 小提琴

CSS 的CSS

header div#h1 h1{
    position: absolute;
    -webkit-animation: flip 5s infinite; /* Safari 4+ */
    -moz-animation:    flip 5s infinite; /* Fx 5+ */
    -o-animation:      flip 5s infinite; /* Opera 12+ */
    animation:         flip 5s infinite; /* IE 10+ */
}

Just a demo example http://jsfiddle.net/6zF4X/2/ 只是一个演示示例http://jsfiddle.net/6zF4X/2/

It wasn't flipping all the way since your last value was 180deg instead of 360deg. 自从您的上一个值是180deg而不是360deg以来,它并没有完全翻转。 I adjusted some of the other deg's, but you should adjust the degrees the way you want. 我已经调整了其他一些度数,但是您应该按照自己的方式调整度数。 Just make sure the first one is 0 and the last is 360. Also, it's best practice to use the same value types throughout the animation. 只需确保第一个是0,最后一个是360。而且,最佳做法是在整个动画中使用相同的值类型。 So I used rotateX(0) for the 0% instead of rotate(0) like you had before. 因此,我将rotateX(0)用作0%,而不是像以前那样使用rotate(0)。

I changed some other stuff around in the fiddle, so don't use that fiddle exactly. 我在小提琴中更改了一些其他内容,因此请不要完全使用该小提琴。 Just change your rotate deg's accoringly and it will work. 只需相应地更改您的旋转角度即可。

@keyframes flip{
    0%{
        transform: rotateX(0);
    }
    25%{
        transform: rotateX(80deg);
    }
    50%{
        transform: rotateX(160deg);
    }
    75%{
        transform: rotateX(280deg);
    }
    100%{
        transform: rotateX(360deg);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM