效果图
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{margin: 0;padding: 0;}
.box{width: 640px;height: 310px;margin:auto;position: relative;margin-top: 5%;}
.a1{position: relative;}
.b1{position: relative;}
.a{width: 310px;height: 310px;background: red;opacity: .5;
border-radius: 50%;position: absolute;left: 0;animation:mymove 2s infinite linear alternate;cursor: pointer;}
.b{width: 310px;height: 310px;background: blue;opacity: .5;
border-radius: 50%;position: absolute;right: 0;animation:mymove1 2s infinite linear alternate;cursor: pointer;}
.a:hover{opacity: 1;}
.b:hover{opacity: 1;}
.left{float: left;}
.right{float: right;}
@keyframes mymove
{
from {left:0px;}
to {left:50px;}
}
@-webkit-keyframes mymove
{
from {left:0px;}
to {left:50px;}
}
@keyframes mymove1
{
from {right:0px;}
to {right:50px;}
}
@-webkit-keyframes mymove1 /*Safari and Chrome*/
{
from {right:0px;}
to {right:50px;}
}
</style>
</head>
<body>
<div class="box">
<div class="left a1">
<div class="a"></div>
</div>
<div class="right b1">
<div class="b"></div>
</div>
<div class="clear"></div>
</div>
</body>
</html>