国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

JavaScript如何實(shí)現自定義動(dòng)畫(huà)

發(fā)布時(shí)間:2021-09-27 17:50 來(lái)源:億速云 閱讀:0 作者:小新 欄目: 開(kāi)發(fā)技術(shù)

這篇文章將為大家詳細講解有關(guān)JavaScript如何實(shí)現自定義動(dòng)畫(huà),小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

自定義動(dòng)畫(huà)用到的幾個(gè)框架函數:

$("Element").animate(params[,duration[,easing[,callback]]])
[quote]用于創(chuàng )建自定義動(dòng)畫(huà)的函數。
這個(gè)函數的關(guān)鍵在于指定動(dòng)畫(huà)形式及結果樣式屬性對象。這個(gè)對象中每個(gè)屬性都表示一個(gè)可以變化的樣式屬性(如“height”、“top”或“opacity”)。 
注意:所有指定的屬性必須用駱駝形式,比如用marginLeft代替margin-left,如果有不懂得駱駝命名法的朋友請看三種通用CSS規范化命名的規則。
而每個(gè)屬性的值表示這個(gè)樣式屬性到多少時(shí)動(dòng)畫(huà)結束。如果是一個(gè)數值,樣式屬性就會(huì )從當前的值漸變到指定的值。如果使用的是“hide”、“show”或“toggle”這樣的字符串值,則會(huì )為該屬性調用默認的動(dòng)畫(huà)形式。
params
(Options) : 一組包含作為動(dòng)畫(huà)屬性和終值的樣式屬性和及其值的集合
duration (String,Number) : (可選) 三種預定速度之一的字符串("slow", "normal", or "fast")或表示動(dòng)畫(huà)時(shí)長(cháng)的毫秒數值(如:1000)
easing (String) : (可選) 要使用的擦除效果的名稱(chēng)(需要插件支持).默認jQuery提供"linear" 和 "swing".
callback (Function) : (可選) 在動(dòng)畫(huà)完成時(shí)執行的函數
$("Element").animate(params,options)
同上
params (Options)
: 一組包含作為動(dòng)畫(huà)屬性和終值的樣式屬性和及其值的集合
options (Options)
: 一組包含動(dòng)畫(huà)選項的值的集合

$("Element").stop()
停止指定元素上正在運行的動(dòng)畫(huà)
$("Element").queue()
返回指向第一個(gè)匹配元素的隊列,常與length配合使用;可以將其理解為數組,一個(gè)動(dòng)畫(huà)數組中包含了好幾個(gè)效果,queue().length表示獲得當前所執行的第一個(gè)效果。

通過(guò)以上函數實(shí)現自定義動(dòng)畫(huà)效果:

(1)實(shí)現一個(gè)動(dòng)畫(huà)queue,在循環(huán)展現每個(gè)動(dòng)畫(huà):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>第二十九節jQuery作業(yè)</title>
<script language="javascript"
	src="js/jquery-1.3.2.js"></script>
<script language="javascript" charset="GB2312">
	$(function() {
		$("#show").click(function() {
			var n = $("div").queue();
			$("span").text("Queue length is: " + $("div").queue().length);
		});
		runIt();
	});

	function runIt() {
		$("div").show("slow");
		$("div").animate({
			left : '+=200'
		}, 2000);
		$("div").slideToggle(1000);
		$("div").slideToggle("fast");
		$("div").animate({
			left : '-=200'
		}, 1500);
		$("div").hide("slow");
		$("div").show(1200);
		$("div").slideUp("normal", runIt);
	}
</script>
<style>
div {
	margin: 3px;
	width: 40px;
	height: 40px;
	position: absolute;
	left: 0px;
	top: 30px;
	background: green;
	display: none;
}

div.newcolor {
	background: blue;
}

span {
	color: red;
}
</style>
</head>
<body>
	<button id="show">Show Length of Queue</button>
	<span></span>
	<div></div>
</body>
</html>

(2)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>第二十九節jQuery作業(yè)</title>
<script language="javascript"
	src="js/jquery-1.3.2.js"></script>
<script language="javascript" charset="GB2312">
	$(function() {
		$(document.body).click(function() {
			$("div").show("slow");
			$("div").animate({
				left : '+=200'
			}, 2000);
			$("div").queue(function() {
				$(this).addClass("newcolor");
				$(this).dequeue();
			});
			$("div").animate({
				left : '-=200'
			}, 500);
			$("div").queue(function() {
				$(this).removeClass("newcolor");
				$(this).dequeue();
			});
			$("div").slideUp();
		})
	});
</script>
<style>
div {
	margin: 3px;
	width: 40px;
	height: 40px;
	position: absolute;
	left: 0px;
	top: 30px;
	background: green;
	display: none;
}

div.newcolor {
	background: blue;
}
</style>
</head>
<body>
	Click here...
	<div></div>
</body>
</html>

(3)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>第二十九節jQuery作業(yè)</title>
<script language="javascript"
	src="js/jquery-1.3.2.js"></script>
<script language="javascript" charset="GB2312">
	$(function() {
		$("#start").click(function() {
			$("div").show("slow");
			$("div").animate({
				left : '+=200'
			}, 5000);
			$("div").queue(function() {
				$(this).addClass("newcolor");
				$(this).dequeue();
			});
			$("div").animate({
				left : '-=200'
			}, 1500);
			$("div").queue(function() {
				$(this).removeClass("newcolor");
				$(this).dequeue();
			});
			$("div").slideUp();
		})

		$("#stop").click(function() {
			$("div").queue("fx", []);
			$("div").stop();
		})
	});
</script>
<style>
div {
	margin: 3px;
	width: 40px;
	height: 40px;
	position: absolute;
	left: 0px;
	top: 30px;
	background: green;
	display: none;
}

div.newcolor {
	background: blue;
}
</style>
</head>
<body>
	<button id="start">Start</button>
	<button id="stop">Stop</button>
	<div></div>
</body>
</html>

(4)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>第二十九節jQuery作業(yè)</title>
<script language="javascript"
	src="js/jquery-1.3.2.js"></script>
<script language="javascript" charset="GB2312">
	$(function() {
		$("button").click(function() {
			$("div").animate({
				left : '+=200px'
			}, 2000);
			$("div").animate({
				top : '0px'
			}, 600);
			$("div").queue(function() {
				$(this).toggleClass("red");
				$(this).dequeue();
			});
			$("div").animate({
				left : '10px',
				top : '30px'
			}, 700);
		});
	});
</script>
<style>
div {
	margin: 3px;
	width: 50px;
	position: absolute;
	height: 50px;
	left: 10px;
	top: 30px;
	background-color: yellow;
}

div.red {
	background-color: red;
}
</style>
</head>
<body>
	<button>Start</button>
	<div></div>
</body>
</html>

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

久久天堂综合亚洲伊人HD妓女| 闺蜜第一次好滑好紧欣欣| 欧美午夜特黄AAAAAA片| 天天爽夜夜爽人人爽| 亚洲AV永久天堂在线观看| 亚洲AV无码不卡无码国产|