jquery動畫有趣的地方見效果圖: 思想: 將圖片設定分割div的背景圖片,控制div的屬性,可以現實有趣的濾鏡效果,本例中展示了一種,有興趣的朋友可以嘗試其他濾鏡的實作。 本例其餘動畫部分,主要利用jquery中提供animate和delay實作。 animate:這個函數的關鍵在於指定動畫形式及結果樣式屬性物件。這個物件中每個屬性都表示一個可以變化的樣式屬性。 delay:設定一個延遲來延遲執行佇列中之後的項目。 實例效果: jquery 動畫 *{margin: 0px;padding: 0px;} #test{width:300px; height: 300px; position: relative; margin: 20px auto 0px;} [Ctrl A 全選 註:如需引入外部Js需刷新才能執行] $(function(){ var test = $("#test"); var html = ''; for(var i=0;i<5;i++){ html+='<div style="width:60px;height:300px;position:absolute;top:0px;left:'+60*i+'px;background:url(/upload/201207/20120725224206212.jpg) '+-60*i+'px 0px no-repeat;">'; } test.prepend(html); test.find("div").eq(0).animate({ "top":"320px"},2000); test.find("div").eq(1).animate({ "top":"320px"},2500); test.find("div").eq(2).animate({ "top":"320px"},3000); test.find("div").eq(3).animate({ "top":"320px"},3500); test.find("div").eq(4).animate({ "top":"320px"},4000); test.find("div").eq(0).delay(5000); test.find("div").eq(4).delay(3000); test.find("div").eq(1).delay(5000); test.find("div").eq(3).delay(4000); test.find("div").eq(2).delay(5000); test.find("div").eq(0).animate({ "left":"-320px","top":"0px","width":"300px","height":"300px"},5000); test.find("div").eq(4).animate({ "left":"320px","top":"0px","width":"300px","height":"300px","background-position":"0px 0px"},5000); test.find("div").eq(1).animate({ "left":"-320px","top":"320px","width":"300px","height":"300px","background-position":"0px 0px"},4500); test.find("div").eq(3).animate({ "left":"320px","top":"320px","width":"300px","height":"300px","background-position":"0px 0px"},4500); test.find("div").eq(2).animate({ "left":"0px","top":"320px","width":"300px","height":"300px","background-position":"0px 0px"},4000); test.find("div").eq(0).delay(2000); test.find("div").eq(4).delay(2000); test.find("div").eq(1).delay(2000); test.find("div").eq(3).delay(2000); test.find("div").eq(2).delay(2000); test.find("div").eq(0).animate({ "left":"0px","top":"0px","width":"300px","height":"300px","background-position":"0px 0px"},5000); test.find("div").eq(4).animate({ "left":"0px","top":"0px","width":"300px","height":"300px","background-position":"0px 0px"},5000); test.find("div").eq(1).animate({ "left":"0px","top":"0px","width":"300px","height":"300px","background-position":"0px 0px"},4500); test.find("div").eq(3).animate({ "left":"0px","top":"0px","width":"300px","height":"300px","background-position":"0px 0px"},4500); test.find("div").eq(2).animate({ "left":"0px","top":"0px","width":"300px","height":"300px","background-position":"0px 0px"},4000); test.find("div").eq(0).delay(2000); test.find("div").eq(4).delay(2000); test.find("div").eq(1).delay(2000); test.find("div").eq(3).delay(2000); test.find("div").eq(2).delay(2000); test.find("div").eq(0).animate({ "left":"0px","top":"300px","width":"60px","height":"300px","background-position":"0px 0px"},5000,function(){test.find("img").css({"position":"absolute","left":"0px","top":"0px","z-index":"999"}); test.find("div").css({"background":"url(/upload/201207/20120725224206323.jpg) no-repeat"});}); test.find("div").eq(4).animate({ "left":"240px","top":"300px","width":"60px","height":"300px","background-position":"-240px 0px"},5000); test.find("div").eq(1).animate({ "left":"60px","top":"200px","width":"60px","height":"300px","background-position":"-60px 0px"},4500); test.find("div").eq(3).animate({ "left":"180px","top":"200px","width":"60px","height":"300px","background-position":"-180px 0px"},4500); test.find("div").eq(2).animate({ "left":"120px","top":"300px","width":"60px","height":"300px","background-position":"-120px 0px"},4000); });