使用CSS样式与jQuery分步骤实现抢车位动画效果
CSS样式定位车图片位置
1、在style.css文件中的11行,输入下面代码:
position: absolute;
2、在style.css文件中的12行,输入下面代码:
top: 0;
3、在style.css文件中的13行,输入下面代码:
left:720px;
用jQuery代码让车动起来
1、在script.js文件中的3行,输入下面代码:
$(".car").animate({left:'0px'},{duration:300});
2、在script.js文件中的5行,输入下面代码:
$(".car").animate({left:'720px'},{duration:300});
<!DOCTYPE html> <html> <head> <title>停车动画</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="style.css" rel="stylesheet" type="text/css"> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> <script type="text/javascript" src="script.js"></script> </head> <body> <div class="boxgrid"> <img class="car" src="http://img1.sycdn.imooc.com//5343d553000107a107200701.jpg" width="350" height="341"/> <img src="http://img1.sycdn.imooc.com//5343d56b0001ccfb07200701.jpg" width="350" height="341"/> </div> </body> </html>
$(document).ready(function(){ $('.boxgrid').hover(function(){ }, function() { }); });
*{ padding:0px; margin:0px; } body{ background:#D5DEE7; } .boxgrid{ width: 720px; height: 701px; border: solid 2px #8399AF; } .boxgrid img.car{ }