jQuery效果-淡入淡出

來源:互聯網
上載者:User

標籤:

本文實現一個控制出現、消失、透明度的效果

 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Insert title here</title> 6    <script src="jquery-3.1.0.min.js"></script> 7    <script src="myjs2.js"></script> 8 </head> 9 <body>10     <button id="in">fadeIn</button><!-- 慢慢出現動畫 -->11     <button id="out">fadeOut</button><!-- 慢慢消失動畫 -->12     <button id="toggle">fadeToggle</button><!-- 一個按鈕直接控制出現/消失動畫 -->13     <button id="to">fadeTo</button><!-- 透明度效果 -->14     <div id="div1" style="width:80px;display:none;height:80px;background-color: aqua"></div>15     <div id="div2" style="width:80px;display:none;height:80px;background-color: #ece023"></div>16     <div id="div3" style="width:80px;display:none;height:80px;background-color: darkgoldenrod"></div>17     18 </body>19 </html>

js:

 1 $(document).ready(function(){ 2     $("#in").on("click",function(){ 3         $("#div1").fadeIn(1000);//fadeIn慢慢出現 4         $("#div2").fadeIn(1000); 5         $("#div3").fadeIn(1000); 6     }); 7      8     $("#out").on("click",function(){ 9         $("#div1").fadeOut(1000);//fadeOut慢慢消失10         $("#div2").fadeOut(1000);11         $("#div3").fadeOut(1000);12     });13     $("#toggle").on("click",function(){14         $("#div1").fadeToggle(1000);//一個按鈕直接控制出現/消失動畫15         $("#div2").fadeToggle(1000);16         $("#div3").fadeToggle(1000);17     });18     $("#to").on("click",function(){19         $("#div1").fadeTo(1000,0.5);//透明度效果,如淡化,1表示完全不透明,0表示完全透明20         $("#div2").fadeTo(1000,0.7);21         $("#div3").fadeTo(1000,0.3);22     });23 });

 

jQuery效果-淡入淡出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.