animate() 是 jQuery 中用來建立自訂動畫的方法。它能讓元素在不同 CSS 狀態之間逐步過渡,例如移動位置、改變透明度或調整字體大小。
$(selector).animate(styles, speed, easing, callback)另一種形式是使用 options 物件:
$(selector).animate(styles, options)只有數字型 CSS 屬性能製作動畫,例如 top、left、width、height、fontSize、opacity 等。顏色或背景圖片這類非數字值,通常無法直接做動畫。
animate() 很適合用來製作滾動、展開、位移與淡入淡出等效果。