jQuery 效果 - animate() 方法

來源:互聯網
上載者:User

標籤:描述   font   高度   tin   額外   文法   slow   options   擴充   

執行個體

改變 "div" 元素的高度:

$(".btn1").click(function(){  $("#box").animate({height:"300px"});});

親自試一試

定義和用法

animate() 方法執行 CSS 屬性集的自訂動畫。

該方法通過CSS樣式將元素從一個狀態改變為另一個狀態。CSS屬性值是逐漸改變的,這樣就可以建立動畫效果。

只有數字值可建立動畫(比如 "margin:30px")。字串值無法建立動畫(比如 " padding: 0px; border: 0px; line-height: 21px;">注釋:使用 "+=" 或 "-=" 來建立相對動畫(relative animations)。

文法 1
$(selector).animate(styles,speed,easing,callback)
參數 描述
styles

必需。規定產生動畫效果的 CSS 樣式和值。

可能的 CSS 樣式值(提供執行個體):

  • backgroundPosition
  • borderWidth
  • borderBottomWidth
  • borderLeftWidth
  • borderRightWidth
  • borderTopWidth
  • borderSpacing
  • margin
  • marginBottom
  • marginLeft
  • marginRight
  • marginTop
  • outlineWidth
  • padding
  • paddingBottom
  • paddingLeft
  • paddingRight
  • paddingTop
  • height
  • width
  • maxHeight
  • maxWidth
  • minHeight
  • minWidth
  • font
  • fontSize
  • bottom
  • left
  • right
  • top
  • letterSpacing
  • wordSpacing
  • lineHeight
  • textIndent

注釋:CSS 樣式使用 DOM 名稱(比如 "fontSize")來設定,而非 CSS 名稱(比如 "font-size")。

speed

可選。規定動畫的速度。預設是 "normal"。

可能的值:

  • 毫秒 (比如 1500)
  • "slow"
  • "normal"
  • "fast"
easing

可選。規定在不同的動畫點中設定動畫速度的 easing 函數。

內建的 easing 函數:

  • swing
  • linear

擴充外掛程式中提供更多 easing 函數。

callback

可選。animate 函數執行完之後,要執行的函數。

如需學習更多有關 callback 的內容,請訪問我們的 jQuery Callback 這一章。

文法 2
$(selector).animate(styles,options)
參數 描述
styles 必需。規定產生動畫效果的 CSS 樣式和值(同上)。
options

可選。規定動畫的額外選項。

可能的值:

  • speed - 設定動畫的速度
  • easing - 規定要使用的 easing 函數
  • callback - 規定動畫完成之後要執行的函數
  • step - 規定動畫的每一步完成之後要執行的函數
  • queue - 布爾值。指示是否在效果隊列中放置動畫。如果為 false,則動畫將立即開始
  • specialEasing - 來自 styles 參數的一個或多個 CSS 屬性的映射,以及它們的對應 easing 函數

jQuery 效果 - animate() 方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.