jQuery 動(dòng)畫基礎(chǔ)教程
更新時(shí)間:2008年12月25日 00:00:08 作者:
用jquery實(shí)現(xiàn)簡單動(dòng)畫的制作,希望看了這篇文章后,建議大家自己手工打打,學(xué)習(xí)一下他的思路。
注意此代碼需要用到j(luò)query的js文件,才可以用所以大家可以先下載一個(gè)jquery文件,注意調(diào)用路徑。
代碼:
<!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>
<title>jQuery動(dòng)畫基礎(chǔ)</title>
<script type="text/javascript" src="../js/jquery-1.2.6.js"></script>
<style type="text/css">
.theImage{
position:relative;
background:Green;
width:100px;
}
</style>
<script type="text/javascript">
$(function(){
$("#btnShow").click(function(){
//$("#block").show(1000);//沒有參數(shù)則沒有動(dòng)畫效果
//$("#block").fadeIn("slow");//根據(jù)透明度顯示或隱藏
$("#block").slideDown();//拉下來。只改變高度
});
$("#btnHide").click(function(){
//$("#block").hide("normal");//slow,normal,fast
//$("#block").fadeOut(5000);
$("#block").slideUp();
});
//自定義動(dòng)畫
$("#btnImage").click(function(){
$("#imageDiv").animate(
//I
//移動(dòng)到的位置,這里的位置是相對(duì)與原來的位置
//top即相對(duì)原來的位置向上移動(dòng)多少距離,沒搞明白,結(jié)果是向下移動(dòng)了。
//{left:"400px",top:"100px"},
//3000
//II
{left:"+=50",width:"300px",height:"200px"},//改變位置的同時(shí)改變寬度高度
3000
);
});
//同時(shí)執(zhí)行兩個(gè)動(dòng)畫,執(zhí)行完一個(gè),然后接著執(zhí)行另一個(gè)。
$("#btnImage").click(function(){
$("#imageDiv").animate(
{left:"100px",width:"30px",height:"20px"},
3000,
function(){alert('callback函數(shù)');}//動(dòng)畫結(jié)束后要執(zhí)行的函數(shù)
);
});
});
</script>
</head>
<body>
<div>
<button id="btnShow"> Show</button>
<button id="btnHide">Hide</button>
<div id="block" style="background:#369; width:150px; height:100px; ">Hello!</div>
<button id="btnImage">moveImage</button>
<div id="imageDiv" class="theImage">image</div>
<div>hi</div>
</div>
</body>
</html>
代碼:
復(fù)制代碼 代碼如下:
<!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>
<title>jQuery動(dòng)畫基礎(chǔ)</title>
<script type="text/javascript" src="../js/jquery-1.2.6.js"></script>
<style type="text/css">
.theImage{
position:relative;
background:Green;
width:100px;
}
</style>
<script type="text/javascript">
$(function(){
$("#btnShow").click(function(){
//$("#block").show(1000);//沒有參數(shù)則沒有動(dòng)畫效果
//$("#block").fadeIn("slow");//根據(jù)透明度顯示或隱藏
$("#block").slideDown();//拉下來。只改變高度
});
$("#btnHide").click(function(){
//$("#block").hide("normal");//slow,normal,fast
//$("#block").fadeOut(5000);
$("#block").slideUp();
});
//自定義動(dòng)畫
$("#btnImage").click(function(){
$("#imageDiv").animate(
//I
//移動(dòng)到的位置,這里的位置是相對(duì)與原來的位置
//top即相對(duì)原來的位置向上移動(dòng)多少距離,沒搞明白,結(jié)果是向下移動(dòng)了。
//{left:"400px",top:"100px"},
//3000
//II
{left:"+=50",width:"300px",height:"200px"},//改變位置的同時(shí)改變寬度高度
3000
);
});
//同時(shí)執(zhí)行兩個(gè)動(dòng)畫,執(zhí)行完一個(gè),然后接著執(zhí)行另一個(gè)。
$("#btnImage").click(function(){
$("#imageDiv").animate(
{left:"100px",width:"30px",height:"20px"},
3000,
function(){alert('callback函數(shù)');}//動(dòng)畫結(jié)束后要執(zhí)行的函數(shù)
);
});
});
</script>
</head>
<body>
<div>
<button id="btnShow"> Show</button>
<button id="btnHide">Hide</button>
<div id="block" style="background:#369; width:150px; height:100px; ">Hello!</div>
<button id="btnImage">moveImage</button>
<div id="imageDiv" class="theImage">image</div>
<div>hi</div>
</div>
</body>
</html>
相關(guān)文章
jQuery網(wǎng)頁定位導(dǎo)航特效實(shí)現(xiàn)方法
這篇文章主要介紹了jQuery網(wǎng)頁定位導(dǎo)航特效實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了jQuery網(wǎng)頁定位導(dǎo)航的功能描述、原理與核心實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-12-12
JQuery插件ajaxfileupload.js異步上傳文件實(shí)例
這篇文章主要介紹了JQuery插件ajaxfileupload.js異步上傳文件實(shí)例,本文直接給出了HTML代碼和JS代碼以及后臺(tái)處理代碼,需要的朋友可以參考下2015-05-05
jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)代碼分享
這篇文章主要介紹了jquery實(shí)現(xiàn)select選擇框內(nèi)容左右移動(dòng)代碼,感興趣的小伙伴們可以參考一下2015-11-11
jQuery事件注冊(cè)的實(shí)現(xiàn)示范
jQuery為我們提供了方便的事件注冊(cè)機(jī)制,它的優(yōu)點(diǎn),操作簡單,且不用擔(dān)心事件覆蓋等問題。缺點(diǎn),普通的事件注冊(cè)不能做事件委托,且無法實(shí)現(xiàn)事件解綁,需要借助其他方法2022-07-07
jquery 圖片預(yù)加載 自動(dòng)等比例縮放插件
在圖片加載前顯示一個(gè)加載標(biāo)志,當(dāng)圖片下載完畢后顯示圖片出來 可對(duì)圖片進(jìn)行是否自動(dòng)縮放功能2008-12-12
基于jquery的一行代碼輕松實(shí)現(xiàn)拖動(dòng)效果
寫JS實(shí)現(xiàn)拖動(dòng)需要一大堆不便維護(hù)的代碼,實(shí)屬麻煩,Google了大半天,發(fā)現(xiàn)了一個(gè)優(yōu)秀的Jquery插件EasyDrag,只需要一行代碼便可輕松在主流瀏覽器上。2010-12-12

