在很多前端的网页动态效果中,我们需要实现一个动态上下回动的效果,下去之后渐渐变慢,回去之后也是先快后缓。
当然,这样的动画使用JS源代码或者其他方法都可以实现,但是有的活血会很复杂,这里提供一种简单的方法实现跳动效果。
算了直接上源码。但是这个必须在高版本浏览器中有用,不得不说万恶的IE,我没有测试其他的浏览器,只是提供了这种方法。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style type="text/css">
*{
margin:0px;
padding: 0px;
}
.box{
width: 500px;
height: 500px;
background: lightblue;
margin:50px auto 0px;
}
.box1{
width: 50px;
height:50px;
background: red;
animation:mymove 1s infinite;
position: relative;
}
@keyframes mymove{
0%{top:0px;}
50%{top:450px;}
100%{top:0px;}
}
</style>
<body>
<div class="box">
<div class="box1">
</div>
</div>
</body>
</html>
拿过去就能直接用,其实也就是让你的动画结束正好回到起点,无限循环下去,再设定好时间就可以实现这种效果了,比起一些使用js或者插件什么的方法可要简单的多了。
当然这个也是有缺陷的,有些浏览器版本是不支持css3 的动画的。
不过我写的这个距离是很大的,你们可以自己写的距离短一些,时间也更改一下。
总能实现你想要的效果。