【问题标题】:Css3 different keyframes for different states不同状态的css3不同的关键帧
【发布时间】:2013-06-12 20:25:54
【问题描述】:

我遇到了一些麻烦 我的第一个动画在页面加载时工作正常,但是我想在你悬停图形元素时触发另一个动画,如果你这样做,第一个动画会重复,但显然,如果你把鼠标放在红色框上并强制它转到原始位置,然后我的第二个动画工作:/

是关键帧元素属于它的第一个位置吗?我做到了绝对,是一样的。 您可以在此处查看工作代码: http://jsfiddle.net/zhk7w/ 谢谢你的手!

<div id="wrapper">
        <article>
            <div id="sharing-wrapper">
                <figure>
                <a class="animate" href="#">p</a>
                </figure>

            </div>
            <div class="test">
                <a class="test" href="">C</a>
            </div>
        </article>
    </div>

还有css:

#sharing-wrapper figure{
margin-left: 50px;
position: relative;
width: 20px;
height: 20px;
}
#sharing-wrapper figure{
padding: 15px;
background-color: red;
position: relative;
-webkit-animation-name:animatetopbottom,animateleft;
-webkit-animation-duration:3s,3s;
-webkit-animation-fill-mode:forwards;
/*-webkit-animation-direction:alternate;*/
}
#sharing-wrapper figure:hover{
-webkit-animation: shakeit 1s;}

动画:

    @-webkit-keyframes animateleft{
    from {left: 0px;}
    to {left: 50px;}
}

@-webkit-keyframes animatetopbottom{
    0% {top: 0px;}
    10% {top: 90px;}
    20% {top: 60px;-webkit-transform:rotate(680grad);}
    30% {top: 90px;-webkit-transform:scale(0.7);}
    40% {-webkit-transform:scale(1.5);}
    50% {top: 60px;-webkit-transform:rotate(0grad);}
    80% {top: 80px;}
    100% {top: 80px;}

}



    @-webkit-keyframes shakeit{
    from { top: 25px; }
    to { top: -40px; }
    }

【问题讨论】:

    标签: css hover css-animations


    【解决方案1】:

    您应该在动画悬停之前延迟动画。

    一旦您将框悬停,它就会从鼠标上移开,并且 :hover 不再是活动状态,下一个或默认动画会立即接管: http://jsfiddle.net/zhk7w/1/

    #sharing-wrapper figure{
        padding: 15px;
        background-color: red;
        position: relative;
        -webkit-animation-delay:1s;
        -webkit-animation-name:animatetopbottom,animateleft;
        -webkit-animation-duration:3s,3s;
        -webkit-animation-fill-mode:forwards;
        /*-webkit-animation-direction:alternate;*/
    }
    

    【讨论】:

    • 感谢您的宝贵时间 :D .. 这有助于,事情是在第一个动画之后,我希望盒子停留在它完成的地方,并且悬停动画发生在同一个地方第一个动画完成,我给了它绝对位置,但盒子回到原来的位置:/
    • tip:动画结束后,原有规则不再覆盖。
    猜你喜欢
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多