jquery動畫(1)

來源:互聯網
上載者:User

標籤:

jQuery基本動畫效果
show()
用於顯示頁面元素與之相對應的hide()
測試案例:
<p title="標題">測試</p>
<ul style="display: none">
<li title=‘蘋果‘>蘋果</li>
<li title=‘橘子‘>橘子</li>
<li title=‘菠蘿‘>菠蘿</li>
</ul>
點擊顯示
$(‘p‘).bind("click",function(){
$("ul").show();
})

點擊轉場效果
$(‘p‘).toggle(function(){
$("ul").show();
},function(){
$("ul").hide()
})

注意這裡可以加參數進去
speed:三種預定速度之一的字串("slow","normal", or "fast")或表示動畫時間長度的毫秒數值(如:1000)

注意這裡toggle()的使用
$(‘#test‘).click(function(){
$("ul").toggle();
})
————————————————
slideDown
$(‘p‘).toggle(function(){
$("ul").slideUp()
},function(){
$("ul").slideDown();
})

這裡注意this關鍵字,因為this屬於js的東西,但是能不能轉為jQuery的東西呢

$(‘#test‘).toggle(function(){
$(this).next().slideUp() ----注意這裡和上邊的寫法不同之處
},function(){
$(this).next().slideDown();
})

注意的和之前的隱藏顯示一樣,這裡也有簡化版
$(‘#test‘).click(function(){
$("ul").slideToggle()
})
——————————————
fadeIn fadeOut---淡入淡出效果
$(‘#test‘).toggle(function(){
$(this).next().fadeOut();
},function(){
$(this).next().fadeIn();
})

注意看API這裡也有它自己的簡潔寫法,使用過程中多多注意

animate()——覺得之前的動畫效果不滿意,好吧,我們看這裡,自訂動畫效果

自訂移動的案例
<div id="test"></div>
#test{
position: absolute;
width: 100px;
height: 100px;
border: 1px solid red;
background-color: gray;
}
$(‘#test‘).click(function(){
$(this).animate({left:"500px"},3000)
})

注意這裡可以添加多個條件的
$(‘#test‘).click(function(){
$(this).animate({left:"200px",height:"200px"},3000)
})
案例2:
<button id="left">?</button> <button id="right">?</button>
<div id="test"></div>

$(‘#left‘).click(function(){
$("#test").animate({left:"-500px"},3000)
})
$(‘#right‘).click(function(){
$("#test").animate({left:"500px"},3000)
})

jquery動畫(1)

聯繫我們

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