6.2 .animate() 函式動畫效果

.animate() 函式

四個參數。

$("div.div_block").animate({
  "width": "200px",
  "height": "300px"
}, 5000, "swing", function(){
  // 動畫效果跑完後,執行這裡
});

第一個參數:帶入要操控的 CSS。

第二個參數:時間,單位是毫秒。

第三個參數,可以是 swing (預設)或 linear (從頭到尾等速)。

第四個參數:帶入匿名函式,動畫效果跑完後,執行匿名函式。

例:

範例:留言區域(介紹 scrollTop)

1、先瞭解 .prop("scrollHeight")

2、瞭解 animate 當中的 scrollTop:

3:建立 chat_interface.html 網頁檔

完成版:

範例:頁面往上滑

Last updated