jQuery--自訂動畫animate()

來源:互聯網
上載者:User

標籤:pos   mat   city   query   pointer   idt   javascrip   opacity   order   

文法結構

animate(params,speed,callback)

params:包含一個樣式屬性及值的映射。比如{property1:‘value1‘,property:‘value2‘,......}

speed:速度參數,可選。

callback:在動畫完成時執行的函數,可選

1、自訂簡單動畫,使元素在3秒(3000毫秒),向右移動500像素

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <style type="text/css">        #panel{            position: relative;            width: 100px;            height: 100px;            border:1px solid black;            background: red;            cursor: pointer;            opacity: 0.5;        }    </style>    <script type="text/javascript" src=‘jquery-3.2.1.min.js‘></script>    <script type="text/javascript">        $(function(){            $(‘#panel‘).click(function(){                $(this).animate({left:‘500px‘},3000)            });        });    </script></head><body>    <div id="panel"></div></body></html>

2、累加、累減動畫

‘-=‘或者‘+=‘表示在當前位置累加或者累減

$(function(){            $(‘#panel‘).click(function(){                $(this).animate({left:‘+=500px‘},3000)          });});

3、多重動畫

  1)、同時執行多個動畫

$(function(){            $(‘#panel‘).click(function(){                $(this).animate({left:‘+=500px‘,height:‘200px‘},3000);            });});

  2)、按順序執行多個動畫

$(function(){            $(‘#panel‘).click(function(){                $(this).animate({left:‘+=500px‘},3000).animate({height:‘200px‘},3000);          });});

4、綜合動畫

單擊div元素,讓他向右移動的同時增加他的高度,並將不透明從50%變成100%,然後在從上到下移動,同時他的寬度變大,當完成這些效果後,讓他以淡出的方式隱藏

$(function(){            $(‘#panel‘).click(function(){                $(this).animate({left:‘500px‘,height:‘200px‘,opacity:‘1‘},3000).animate({top:‘100px‘,width:‘200px‘},3000).fadeOut(3000);            });});

5、回呼函數

最後一步切換div的CSS樣式

$(function(){              $(‘#panel‘).click(function(){                  $(this).animate({left:‘500px‘,height:‘200px‘,opacity:‘1‘},3000).animate({top:‘100px‘,width:‘200px‘},3000,function(){                      $(this).css(‘border‘,‘10px solid black‘);                  });            });});

 

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.