jQuery動畫特效執行個體教程

來源:互聯網
上載者:User

標籤:

本文以執行個體形式詳細講述了jQuery動畫特效的實現方法。

1.自製摺疊內容塊

內容塊如下:

 
  <div class="module">  <div class="caption">    <span>標題</span>    <img src="rollup.gif" alt="rollup" title="rolls up this module"/>  </div>  <div class="body">    春江彼岸兩大明星產品之一:超越型複式,在春江酈城97複式基礎上再升級,終點: 春江彼岸兩大明星產品之一:超越型複式,在春江酈城97複式基礎上再升級,終點: 春江彼岸兩大明星產品之一:超越型複式,在春江酈城97複式基礎上再升級,終點: 春江彼岸兩大明星產品之一:超越型複式,在春江酈城97複式基礎上再升級,終點: 春江彼岸兩大明星產品之一:超越型複式,在春江酈城97複式基礎上再升級,終點: 春江彼岸兩大明星產品之一:超越型複式,在春江酈城97複式基礎上再升級,終點.
  </div></div>

給img元素繫結點擊事件。

$(function() {  $(‘div.caption img‘).click(function () { //先找到img的父級元素,再找該父級元素的子項目 var $body = $(this).closest(‘div.module‘).find(‘div.body‘); if ($body.is(‘:hidden‘)) {   $body.show(); } else {   $body.hide(); }  });}); 切換元素的顯示狀態,還可以用toggle方法。$(function() {  $(‘div.caption img‘).click(function () { $(this).closest(‘div.module‘).find(‘div.body‘).toggle();  });});以上是沒有動畫效果的,有時候感覺會很唐突。實際上,show,hide,toggle方法都可以有動畫效果。比如:$(function() {  $(‘div.caption img‘).click(function () { $(this).closest(‘div.module‘).find(‘div.body‘).toggle(‘slow‘);  });});又比如:$(function() {  $(‘div.caption img‘).click(function () { $(this).closest(‘div.module‘).find(‘div.body‘).toggle(‘slow‘, function() {   $(this).closest(‘div.module‘).toggleClass(‘rolledup‘, $(this).is(‘:hidden‘)) });  });}); 2.使元素淡入淡出fadeIn(speed, callback)    fadeOut(speed, callback)fadeTo(speed, opacity, callback) 3.上下滑動元素slideDown(speed, callback)slideUp(speed, callback)slideToggle(speed, callback) 4.停止動畫stop(clearQueue, gotoEnd)  5.建立自訂動畫animate(properties, duration, easing, callback) $(‘.classname‘).animate({opacity:‘toggle‘},‘slow‘)如果寫一個擴充函數。$.fn.fadeToggle = function(speed){  return this.animate({opacity:‘toggle‘},‘slow‘);} 6.自訂縮放動畫$(‘.classname‘).each(function(){  $(this).animate({    width: $(this).width() * 2,    height: $(this).height() * 2  });}); 7.自訂掉落動畫$(‘.classname‘).each(function(){  $(this)    .css("position","relative")    .animate({      opacity: 0,      top: $(window).height() - $(this).height() - $(this).position().top    },‘slow‘,function(){ $(this).hide(); })}); 8.自訂消散動畫$(‘.classname‘).each(function(){  var position = $(this).position();  $(this)    .css({      position: ‘absolute‘,      top: position.top,      left:position.left    })    .animate({      opacity: ‘hide‘,      width: $(this).width()*5,      height: $(this).height()*5      top: position.top - ($(this).height() * 5 / 2),      left: position.left - ($(this).width() * 5 /2)    },‘normal‘);}); 9.隊列中的動畫//動畫插入隊列$(‘img‘).queue(‘chain‘, function(){});$(‘img‘).queue(‘chain‘, function(){});$(‘img‘).queue(‘chain‘, function(){});$(‘img‘).queue(‘chain‘, function(){}); $(‘button‘).click(function(){  $(‘img‘).dequeue(‘chain‘); //刪除隊列中的動畫}) cleaeQueue(name)//刪除所有未執行的隊列中的動畫delay(duration, name)//為隊列中所有未執行的動畫添加延遲      

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.