jQuery中的事件與動畫

來源:互聯網
上載者:User

標籤:mouseover   控制   span   speed   透明   eve   動畫   selector   button   

 一    基礎事件

   1 jQuery中典型的事件方法

     單擊事件  click(fn)

     按下鍵盤觸發事件    kendown(fn) 

     失去焦時間點事件   blur(fn)

   2 常用的滑鼠事件方法

     click(fn)  單擊滑鼠

     mouseover(fn)  滑鼠指標移過時

     mouseout(fn)   滑鼠指標移出時

   3 鍵盤事件

     keydown(fn)   按下鍵盤時

     keyup(fn)    釋放鍵盤時

     keypress()   產生可列印的字元時

   4 表單事件

     focus()   獲得焦點

     blur()     失去焦點

   5 綁定事件與移除事件

      文法 : bind(type,[data],fn)

     綁定一個事件

       

$("button").bind("click",function(){  $("p").slideToggle();});

   綁定多個事件

$(selector).bind({event:function, event:function, ...})

 移除事件

      文法 :unbind([type],[fn]);

   

$("button").click(function(){  $("p").unbind();});

  複合事件

    hover()方法

      文法:hover(enter,leave);

   當滑鼠指標懸停在上面時,改變 <p> 元素的背景顏色:

$("p").hover(function(){    $("p").css("background-color","yellow");},function(){    $("p").css("background-color","pink");}); 

  toggle()方法

       文法:  toggle(f1,f2);

  二  jQuery中的動畫

     1 控制元素顯示與隱藏

        顯示文法 : $(selector).show([speed],[callback]);

$(".btn2").click(function(){  $("p").show();});

 

        隱藏文法 :   $(selector).hide([speed],[callback]);

$(".btn2").click(function(){  $("p").hide();});

  2  改變元素的透明度

       淡入文法: $(selector).fadeIn([speed],[callback]);

  

$(".btn2").click(function(){  $("p").fadeIn();});

  淡出文法 :$(selector).fadeOut([speed],[callback]);

$(".btn2").click(function(){  $("p").fadeOut();});

  

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.