发布于 2016-02-10 21:56:16
JQuery动画
下面是一个使用JQuery和CSS的示例。我使用的是火箭图标(),因为飞机图标不能可靠地显示在我的计算机上(✈️←,我所能看到的只有一个矩形框)。
$(document).ready(function(){
$("#plane-icon").click(function(){
$(this).animate({
left:'180px',
top:'-20px',
fontSize:'20px'
},2000);
$(this).animate({
left:'0px',
top:'180px',
fontSize:'100px'
},0);
$(this).animate({
left:'0px',
top:'80px',
},1000);
});
});.icon-wrap {
width:180px;
height:180px;
font-size:100px;
cursor:pointer;
position:relative;
overflow:hidden;
}
#plane-icon {
position:absolute;
top:80px;
left:0px;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="icon-wrap">
<span id="plane-icon"></span>
</div>
CSS动画
下面是使用CSS关键帧动画完成的相同的动画,而不是JQuery的animate()函数。animationend事件触发器用于在对象完成动画后重置它的CSS类。
$(document).ready(function(){
$('body').on('webkitAnimationEnd oanimationend oAnimationEnd msAnimationEnd animationend',
function(){
$('#plane-icon').removeClass('launched');
}
);
$('#plane-icon').click(function(){
$(this).addClass('launched');
});
});.icon-wrap {
width:180px;
height:180px;
font-size:100px;
overflow:hidden;
}
#plane-icon {
display:block;
cursor:pointer;
transform:translate(0px,80px) scale(1);
}
#plane-icon.launched {
animation-name:rocket;
animation-duration:3s;
cursor:default;
}
@keyframes rocket {
0% {
transform:translate(0px,80px) scale(1);
}
66% {
transform:translate(120px,-80px) scale(0.1);
}
67% {
transform:translate(120px,180px) scale(0.1);
}
68% {
transform:translate(0px,180px) scale(1);
}
100% {
transform:translate(0px,80px) scale(1);
}
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="icon-wrap">
<span id="plane-icon"></span>
</div>
发布于 2016-02-10 22:00:24
好的!不管是字体图标还是SVG图标,您仍然可以使用CSS动画元素。
下面是一个动画示例:
@keyframes fly {
0% {
transform: scale(1);
}
25% {
transform: scale(0.5);
}
100% {
transform: scale(0.5) translate(100vw, -100vh);
}
}
.plane {
display: inline-block;
fill: #e24145;// for demo purposes, only applies to SVGs
&.is-active {
animation-name: fly;
animation-duration: 1.5s;
animation-fill-mode: forwards;
animation-timing-function: ease-in;
}
}工作演示http://codepen.io/tedw/pen/PZXjYv
https://stackoverflow.com/questions/35326343
复制相似问题