国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

jQuery Chinese Reference Manual / jQuery 動(dòng)畫

jQuery 動(dòng)畫

jQuery 效果- 動(dòng)畫


jQuery 動(dòng)畫 - animate() 方法

jQuery animate() 方法用于創(chuàng)建自定義動(dòng)畫。

語法:

$(selector).animate({params},speed,callback);

必需的 params 參數(shù)定義形成動(dòng)畫的 CSS 屬性。

可選的 speed 參數(shù)規(guī)定效果的時(shí)長(zhǎng)。它可以取以下值:"slow"、"fast" 或毫秒。

可選的 callback 參數(shù)是動(dòng)畫完成后所執(zhí)行的函數(shù)名稱。

下面的例子演示 animate() 方法的簡(jiǎn)單應(yīng)用。它把 <div> 元素往右邊移動(dòng)了 250 像素:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({left:'250px'});
  });
});
</script> 
</head>
 
<body>
<button>開始動(dòng)畫</button>
<p>默認(rèn)情況下,所有的 HTML 元素有一個(gè)靜態(tài)的位置,且是不可移動(dòng)的。 
如果需要改變?yōu)椋覀冃枰獙⒃氐?nbsp;position 屬性設(shè)置為 relative, fixed, 或 absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

注:默認(rèn)情況下,所有 HTML 元素都有一個(gè)靜態(tài)位置,且無法移動(dòng)。
如需對(duì)位置進(jìn)行操作,要記得首先把元素的 CSS position 屬性設(shè)置為 relative、fixed 或 absolute!    


jQuery animate() - 操作多個(gè)屬性

請(qǐng)注意,生成動(dòng)畫的過程中可同時(shí)使用多個(gè)屬性:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({
      left:'250px',
      opacity:'0.5',
      height:'150px',
      width:'150px'
    });
  });
});
</script> 
</head>
 
<body>
<button>開始動(dòng)畫</button>
<p>默認(rèn)情況下,所有的 HTML 元素有一個(gè)靜態(tài)的位置,且是不可移動(dòng)的。 
如果需要改變?yōu)椋覀冃枰獙⒃氐?nbsp;position 屬性設(shè)置為 relative, fixed, 或 absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

注:可以用 animate() 方法來操作所有 CSS 屬性嗎?

是的,幾乎可以!不過,需要記住一件重要的事情:當(dāng)使用 animate() 時(shí),必須使用 Camel 標(biāo)記法書寫所有的屬性名,比如,必須使用 paddingLeft 而不是 padding-left,使用 marginRight 而不是 margin-right,等等。

同時(shí),色彩動(dòng)畫并不包含在核心 jQuery 庫(kù)中。

如果需要生成顏色動(dòng)畫,您需要從 jquery.com 下載 顏色動(dòng)畫 插件。


jQuery animate() - 使用相對(duì)值

也可以定義相對(duì)值(該值相對(duì)于元素的當(dāng)前值)。需要在值的前面加上 += 或 -=:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({
      left:'250px',
      height:'+=150px',
      width:'+=150px'
    });
  });
});
</script> 
</head>
 
<body>
<button>開始動(dòng)畫</button>
<p>默認(rèn)情況下,所有的 HTML 元素有一個(gè)靜態(tài)的位置,且是不可移動(dòng)的。 
如果需要改變?yōu)?,我們需要將元素?nbsp;position 屬性設(shè)置為 relative, fixed, 或 absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

jQuery animate() - 使用預(yù)定義的值

您甚至可以把屬性的動(dòng)畫值設(shè)置為 "show"、"hide" 或 "toggle":

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    $("div").animate({
      height:'toggle'
    });
  });
});
</script> 
</head>
 
<body>
<button>開始動(dòng)畫</button>
<p>默認(rèn)情況下,所有的 HTML 元素有一個(gè)靜態(tài)的位置,且是不可移動(dòng)的。 
如果需要改變?yōu)?,我們需要將元素?nbsp;position 屬性設(shè)置為 relative, fixed, 或 absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


jQuery animate() - 使用隊(duì)列功能

默認(rèn)地,jQuery 提供針對(duì)動(dòng)畫的隊(duì)列功能。

這意味著如果您在彼此之后編寫多個(gè) animate() 調(diào)用,jQuery 會(huì)創(chuàng)建包含這些方法調(diào)用的"內(nèi)部"隊(duì)列。然后逐一運(yùn)行這些 animate 調(diào)用。

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    var div=$("div");
    div.animate({height:'300px',opacity:'0.4'},"slow");
    div.animate({width:'300px',opacity:'0.8'},"slow");
    div.animate({height:'100px',opacity:'0.4'},"slow");
    div.animate({width:'100px',opacity:'0.8'},"slow");
  });
});
</script> 
</head>
 
<body>
<button>開始動(dòng)畫</button>
<p>默認(rèn)情況下,所有的 HTML 元素有一個(gè)靜態(tài)的位置,且是不可移動(dòng)的。 
如果需要改變?yōu)?,我們需要將元素?nbsp;position 屬性設(shè)置為 relative, fixed, 或 absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

下面的例子把 <div> 元素往右邊移動(dòng)了 100 像素,然后增加文本的字號(hào):

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script> 
$(document).ready(function(){
  $("button").click(function(){
    var div=$("div");  
    div.animate({left:'100px'},"slow");
    div.animate({fontSize:'3em'},"slow");
  });
});
</script> 
</head>
 
<body>
<button>開始動(dòng)畫</button>
<p>默認(rèn)情況下,所有的 HTML 元素有一個(gè)靜態(tài)的位置,且是不可移動(dòng)的。 
如果需要改變?yōu)?,我們需要將元素?nbsp;position 屬性設(shè)置為 relative, fixed, 或 absolute!</p>
<div style="background:#98bf21;height:100px;width:200px;position:absolute;">HELLO</div>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例