我试图用CSS翻译做以下工作:
当一个按钮被点击,气球出现并飞走。当它们完成飞行时,它们会消失并返回起始位置(因此,当下一次单击按钮时,同样的行为就会发生)。
到目前为止,我还得到了下面是 (气球只会飞起来,不会出现/消失)。
<div>
<img class="object" src="http://pngimg.com/upload/balloon_PNG580.png" />
</div>
<br><br><button id="button">Fly!!!</button>CSS
div{
height: 300px;
position: relative;
}
.object {
width: 60px;
position: absolute;
bottom: 0;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
}
.move-up{
transform: translate(0,-150px);
-webkit-transform: translate(0,-150px);
-o-transform: translate(0,-150px);
-moz-transform: translate(0,-150px);
}JS
$('#button').click(function(){
$('.object').addClass('move-up');
});问题是,当我尝试将启动display : none添加到object并单击add $('.object').show()时,我的动画根本没有启动。我的气球怎么飞?
发布于 2014-08-01 07:57:36
您可以使用CSS3动画实现此效果。有关每个项目的更多细节,请参阅内联评论。
CSS:
.object {
width: 60px;
position: absolute;
bottom: 0;
opacity: 0; /* make the balloon invisible on load and once animation is complete */
}
.move-up{
-webkit-animation: balloon 1s linear; /* the animation to move up */
-moz-animation: balloon 1s linear;
animation: balloon 1s linear;
}
@keyframes balloon { /* included only unprefixed version to keep answer short, demo has the prefixed versions also */
5% {
transform: translate(0, 0); /* keep at original position */
opacity: 1; /* make opacity as 1 after a short time for balloon to appear */
}
50% {
transform: translate(0, -150px); /* move up */
opacity: 1; /* retain the opacity */
}
55%, 100% {
transform: translate(0, -150px); /* retain translated position till end */
opacity: 0; /* hide the ballons and make it hidden for the rest of the duration */
}
}jQuery:
$('#button').click(function(){
$('.object').addClass('move-up'); // adding the move up animation class to make it move
$('.object.move-up').on('animationend webkitAnimationEnd MSAnimationEnd oAnimationEnd',function(){
$('.object').removeClass('move-up'); // removing the animation class on animation end to make it come back to original state
});
});发布于 2015-11-03 11:56:14
我在动画中使用翻译属性制作了一个代码页。(我的集装箱高度700 My)。
@keyframes moveballoon {
0% { transform: translate(0px, 700px);}
100% { transform: translate(0px, -1200px);}
}
.animationballoon {
animation: moveballoon 2s infinite linear forwards;
}使用Jquery,您可以获得如下内容:
$('#button').click(function(){
$('.object').addClass('animationballoon');
});希望能帮上忙!
https://stackoverflow.com/questions/25074789
复制相似问题