JQuery 動畫效果

來源:互聯網
上載者:User

標籤:

//顯示和隱藏 show()  hide() 方法也可以沒有任何參數 只是顯示和隱藏

$("#btnid").bind("click",function(){

     $("#divid").show("slow",function(){ //show方法用於顯示元素 第一個參數是顯示的速度,第二個參數是可選的 顯示完成後執行該函數

         alert("哈哈哈");

});

});

$("#btnid").bind("dbclick",function(){

   $("#divid").hide("fast",function(){//hide方法用於隱藏元素 第一個參數是隱藏的速度,第二個參數是可選的 隱藏完成後執行該函數

       alert("嘿嘿嘿");

});

});

 

//toggle() 顯示或隱藏

$("#btnid").bind("click",function(){  //為btn綁定click事件

         $("divid").toggle("fast",function(){  //如果div是隱藏的  點擊按鈕時div顯示出來,如果div是顯示的 點擊按鈕時div隱藏起來

              $(this).val()=="隱藏"?$(this).val("顯示"):$(this).val("隱藏");  //設定btn的顯示val

          });

});

 

//slideUp() 只用於已經顯示的元素 向上滑動  slideDown() 只用於已經隱藏的元素 向下滑動

$("#btnid").bind("click",function(){

         if($(this).val()=="隱藏"){

              $("#divid").slideUp("fast",function(){  //把顯示出來的div隱藏起來

                    $("#btnid").val("顯示");      //隱藏之後把btn的val設定為顯示

               });

        } else{

               $("#divid").slideDown("slow",function(){ //把隱藏的div顯示出來

                    $("#btnid").val("隱藏");    //顯示出來後把btn的val設定為隱藏

              });

             }  

});

 

//slideToggle()  向上或向下滑動

$("#btnid").bind("click",function(){

        $("#div").slideToggle("fast",function(){  //如果div是顯示的則隱藏  隱藏的話則顯示

              $("#btnid").val()=="向下滑動"?$("#btnid").val("向上滑動"):$("#btnid").val("向下滑動");

        });

});

 

//fadeIn() 淡入(載入顯示) fadeOut() 淡出(隱藏)

$("#btnid").bind("click",function(){

         if($(this).val()=="淡入"){

               $("#divid").fadeIn("fast",function(){

                       $(this).val("淡出");

               });

          }   else{

                 $("#divid").fadeOut("fast",function(){

                          $(this).val("淡入");

                 });

            }

});

 

//fadeTo()  設定淡入淡出  透明

$("span").each(function(index){

         switch(index){

         case 0:

               $(this).fadeTo("fast",0.2,function(){    //第一個參數是淡入淡出的速度 第二個參數是透明度 0.0~1.0之間  第三個是回呼函數(可選的參數)

                        alert("哈哈哈");     

                  });break;

        case 1:

               $(this).fadeTo("fast",0.5,function(){

                        alert("哈哈哈");     

                  });break;

         case 2:

               $(this).fadeTo("fast",0.9,function(){

                        alert("哈哈哈");     

                  });break;

         }

});

 

//animate() 自訂動畫效果

$("span").animate({width:"80px",height:"80px"},3000,function(){  

                         //第一個參數可選 設定的樣式 多個樣式之間用逗號分隔開,第二個參數是動畫的速度 以毫秒為單位,第三個參數是可選的  回呼函數

          $("#divid").html("動畫完成");

});

 

//animate() 移動位置

$("span").animate({width:"+=80px",height:"+=80px"},3000,function(){  //向右下角移動80px 80px

                         //第一個參數可選 設定的樣式 多個樣式之間用逗號分隔開,第二個參數是動畫的速度 以毫秒為單位,第三個參數是可選的  回呼函數

          $("#divid").html("動畫完成");

});

 

//stop()方法停止動畫事件

$("#divid").stop(false,false); //二個參數都是可選的 第一個表示是否停止當前的動畫  第二個表示是否完成正在執行的動畫

 

//delay()方法延遲動畫時間

$("#divid").delay(2000); // 將div的動畫延遲兩秒  單位是毫秒

 

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.