一:jQuery 函數建立自定義動畫的語法:javascript
$(selector).animate({params},[duration],[easing],[callback])
關鍵的參數是 params。它定義產生動畫的 CSS 屬性。能夠同時設置多個此類屬性,以下:html
animate({width:"70%",opacity:0.4,marginLeft:"0.6in",fontSize:"3em"});
OK,相關須要用到的Jquery知識咱們已經講了,那麼接下來看實例:java
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" src="jquery-1.6.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#action").click(function(){
//注意animate修不了顏色
$("#con").animate({"height":"300px","margin-top":"200px"},"slow");
$("#con").animate({"width":"300px","margin-left":"200px"},"slow");
$("#con").animate({"height":"100px","margin-top":"10px"},"slow");
$("#con").animate({"width":"100px","margin-left":"10px"},"slow");
})
})
</script>
<style>
div{
margin:10px;
color:#EFF2A8
}
</style>
<title>Jquery animate動畫</title>
</head>
<body>
<div><a href="#" id="action">Start to animation</a></div>
<div style="background:#00FF00;width:100px; height:100px;" id="con"></div>
</body>
</html>
以下,當咱們點擊「Start to animation」時,那麼將開始動畫,注意要先引入Jquery庫,不然效果顯示不出來。jquery