---
title: "jQuery学习第六课(jquery中的动画)"
author: "mywebcode"
date: "2014-04-09T16:36:00Z"
tags: []
slug: "jquery-jquery"
draft: false
lastmod: "2014-04-19T16:32:56Z"
id: 2049266
url: "https://mywebcode.iteye.com/blog/2049266"
---

﻿﻿

1.基础动画

2.渐变动画

3.滑动动画

4.自定义动画

5.动画队列

**• jquery中的基础动画**(略，见前面的课)

a. show()显示

b. hide()隐藏

c. toggle()切换show/hide

**• jquery中的渐变动画**

a. fadeIn()

b. fadeOut()

c. fadeTo()

d. fadeToggle()切换fadeIn/fadeOut

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)" xml:lang="en"&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8"&gt;  
&lt;title&gt;demo6&lt;/title&gt;  
&lt;script src="jquery.js"&gt;&lt;/script&gt;  
&lt;style&gt;  
p{  
width: 300px;  
padding: 10px;  
border: 1px solid #abcdef;  
/\*display: none;\*/  
}  
&lt;/style&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;a href="###"&gt;点击&lt;/a&gt;  
&lt;p&gt;Javascript是一种由Netscape的LiveScript发展而来的原型化继承的面向对象的动态类型的区分大小写的客户端脚本语言，主要目的是为了解决服务器端语言，比如Perl，遗留的速度问题，为客户提供更流畅的浏览效果。当时服务端需要对数据进行验证，由于网络速度相当缓慢，只有28.8kbps，验证步骤浪费的时间太多。于是Netscape的浏览器Navigator加入了Javascript，提供了数据验证的基本功能。&lt;/p&gt;

&lt;script&gt;  
/\*$('a').click(function(){  
//透明度opacity从0变成1  
$('p').fadeIn(1000);  
});\*/

/\*$('a').click(function(){  
//透明度opacity从1变成0  
$('p').fadeOut(1000);  
})\*/

/\*$('a').click(function(){  
$('p').fadeTo(1000,.3,function(){  
alert('fadeTo方法执行完成');  
});  
});\*/

$('a').click(function(){  
$('p').fadeToggle(500);  
});  
&lt;/script&gt;  
&lt;/body&gt;  
&lt;/html&gt;

**• jquery中的滑动动画**

a. slideDown()

b. slideUp()

c. slideToggle()

&lt;script&gt;  
/\*$('a').click(function(){  
$('p').slideDown(500);//向下滑动显示隐藏的元素  
});\*/

/\*$('a').click(function(){  
$('p').slideUp(500););//与slideDown相反，向上收起隐藏显示的元素  
});\*/

$('a').click(function(){  
$('p').slideToggle(500);//切换slideDown/slideUp  
});  
&lt;/script&gt;

**•** **animate自定义动画**

**• jquery中的动画队列**

stop()

dequeue()

finish()

delay()

jQuery.fx.interval()，设置运动的时间，不推荐

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)" xml:lang="en"&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8"&gt;  
&lt;title&gt;demo9&lt;/title&gt;  
&lt;script src="jquery.js"&gt;&lt;/script&gt;  
&lt;style&gt;  
p{  
width: 300px;  
height: 300px;  
background: #abcdef;  
display: none;  
}  
&lt;/style&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;a href="###"&gt;aaaaaa&lt;/a&gt;  
&lt;p&gt;bbbbbbbbb&lt;/p&gt;

&lt;script&gt;  
$('a').hover(function(){  
$('p').stop(false,true).slideDown(500);  
},function(){  
$('p').stop(false,true).slideUp(500);  
});  
&lt;/script&gt;  
&lt;/body&gt;  
&lt;/html&gt;

\---------------------------------------------------------------------------------------------------------

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)" xml:lang="en"&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8"&gt;  
&lt;title&gt;demo10&lt;/title&gt;  
&lt;style&gt;  
div{  
width: 50px;  
height: 50px;  
background: #f60;  
position: absolute;  
left: 10px;  
top: 40px;  
}  
&lt;/style&gt;  
&lt;script src="jquery.js"&gt;&lt;/script&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;button&gt;RUN&lt;/button&gt;  
&lt;input id="stop" type="button" value="stop" /&gt;  
&lt;input id="dequeue" type="button" value="dequeue" /&gt;  
&lt;input id="finish" type="button" value="finish" /&gt;  
&lt;div&gt;&lt;/div&gt;

&lt;script&gt;  
$('button').click(function(){  
$('div').animate({  
'top':'400px'  
},2000).animate({  
'left':'800px'  
},2000).animate({  
'top':'40px'  
},2000).animate({  
'left':'10px'  
},2000);  
});

$('#stop').click(function(){  
$('div').stop(false,true);  
});

$('#dequeue').click(function(){  
$('div').dequeue();  
});

$('#finish').click(function(){  
$('div').finish();  
});  
&lt;/script&gt;  
&lt;/body&gt;  
&lt;/html&gt;

**• jquery动画算法插件**

先要下载easing插件。

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)"&gt;  
&lt;html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)" xml:lang="en"&gt;  
&lt;head&gt;  
&lt;meta http-equiv="Content-Type" content="text/html;charset=UTF-8"&gt;  
&lt;title&gt;demo12&lt;/title&gt;  
&lt;script src="jquery.js"&gt;&lt;/script&gt;  
&lt;script src="easing.js"&gt;&lt;/script&gt;  
&lt;style&gt;  
div{  
width: 50px;  
height: 50px;  
position: absolute;  
left: 10px;  
top: 40px;  
background: #abcdef;  
}  
&lt;/style&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;input type="button" value="点击" /&gt;  
&lt;div&gt;&lt;/div&gt;

&lt;script&gt;  
$('input').click(function(){  
$('div').animate({'left':'800px'},2000,'easeOutBounce');  
});  
&lt;/script&gt;  
&lt;/body&gt;  
&lt;/html&gt;

//jquery中函数的参数有‘easing’这一项，即可用easing插件中的方法，

表示元素在动画中的过渡时使用的缓动函数。

&lt;body&gt;  
&lt;input type="button" value="点击" /&gt;  
&lt;div&gt;&lt;/div&gt;

&lt;script&gt;  
$('input').click(function(){  
$('div').animate({'left':'-=100px'},2000);  
});  
&lt;/script&gt;  
&lt;/body&gt;