jQuery學習——動畫效果

來源:互聯網
上載者:User

標籤:jquery   javascript   動畫   庫   js   

動畫效果


基本動畫效果隱藏匹配元素

$("img").hide(300);//將img隱藏300ms


顯示匹配元素

$("img").show(300);//在300ms內顯示img

元素狀態切換

$(document).ready(function(){$("input[type='button']").click(function(){$("div").toggle();//若果元素可見,切換為隱藏,如果元素隱藏,切換為可見}});

淡入淡齣動畫效果滑動效果

$("img").fadeIn(300);//淡入$("img").fadeOut(300);//淡出$("img").fadeTo(300,0.5);//在0.5秒內將圖片顯示到15%不透明

滑動顯示

$("#m").slideDown(500);//在500ms內滑動顯示頁面的id為m的元素$("#m").slideUp(500);//在500ms內滑動隱藏頁面中id為m的元素$("#flag").click(function(){$("menu").slideToggle(500);//顯示/隱藏菜單});

方法



eg

1.在建立檔案中引入jQuery庫

<script type="text/javascript" src="JS/jquery-1.6.1.min.js"></script>
2.在<body>定義主體,顯示介面

<body><div id="top"></div><dl><dt>1</dt><dd>        <div class="item">1.1</div>        <div class="item">1.2</div></dd><dt>2</dt><dd>        <div class="item">2.1</div>        <div class="item">2.2</div>        <div class="item">2.3</div></dd><dt>3</dt><dd>        <div class="item">3.1</div>        <div class="item">3.2</div>        <div class="item">3.3</div></dd>    <dt class="title"><a href="#">exit</a></dt></dl><div id="bottom"></div></body>
3.CSS

<style type="text/css">dl {width: 158px;margin:0px;}dt {font-size: 14px; padding: 0px; margin: 0px; width:146px; height:19px; background-image:url(images/title_show.gif);/*設定背景圖片*/padding:6px 0px 0px 12px;color:#215dc6;font-size:12px;cursor:hand;}dd{color: #000;font-size: 12px;margin:0px; }a {text-decoration: none;/*不顯示底線*/}a:hover {color: #FF6600;}#top{width:158px; height:30px; background-image:url(images/top.gif);}#bottom{width:158px; height:31px; background-image:url(images/bottom.gif);}.title{background-image:url(images/title_quit.gif);}.item{width:146px; height:15px; background-image:url(images/item_bg.gif);padding:6px 0px 0px 12px;color:#215dc6;font-size:12px;cursor:hand;background-position:center;background-repeat:no-repeat;}</style>

4.編寫jQuery代碼

<script type="text/javascript">$(document).ready(function(){$("dd").hide(); //隱藏全部子功能表$("dt[class!='title']").toggle(function(){        $(this).css("backgroundImage","url(images/title_hide.gif)");//改變主菜單的背景$(this).next().slideDown("slow");},function(){$(this).css("backgroundImage","url(images/title_show.gif)");//改變主菜單的背景$(this).next().slideUp("slow");});});</script>
運行結果










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.