亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery動畫效果

asal 2019-01-23 11:30:45 275
abstrak:第一章 jQuery顯示/隱藏     hide() 隱藏顯示的元素    書寫格式:hide([speed][sesing] [fn])    show() 顯示隱藏的元素    書寫格式:show([speed][sesing] [fn])    speed:顯示過程的速度 速

第一章 jQuery顯示/隱藏


     hide() 隱藏顯示的元素

    書寫格式:hide([speed][sesing] [fn])

    show() 顯示隱藏的元素

    書寫格式:show([speed][sesing] [fn])

    speed:顯示過程的速度 速度是毫秒值

    sesing:指定切換的效果

    fn:動畫完成時執(zhí)行的一個函數(shù)

<!DOCTYPE html>
<html>
<head>
	<title>jQuery顯示/隱藏</title>
	<meta charset="utf-8">
	<script type="text/javascript" src="jquery-3.3.1.js"></script>
	<style type="text/css">
	 div,p{width: 200px;height: 200px;background: red;margin: 10px 0;color: #fff;}
	</style>
</head>
<body>
	<script type="text/javascript">
		$(document).ready(function(){
			$('#bt1').click(function(){
				$('p').hide('2000')
			})
			$('#bt2').click(function(){
				$('p').show('2000')
			})
		})
	</script>
</body>
	<button id="bt1">點(diǎn)擊隱藏</button>
	<button id="bt2">點(diǎn)擊顯示</button>
	<!-- <div></div> -->
	<p>紅玫瑰與白玫瑰</p>
	<p>朱砂痣與白月光</p>
</html>

第二章 jQuery的滑動


     jQuery的滑動是通過高度的變化(向某個方向增大或者縮?。﹣韯討B(tài)的顯示所匹配的元素


     slideDown([speed] [fn])通過高度的變化,向下增大的動態(tài)效果 下滑效果

     speed:下滑顯示過程的速度 英文值或者毫秒

     fn:動畫完成時執(zhí)行是函數(shù)

<!DOCTYPE html>
<html>
<head>
	<title>jQuery滑動</title>
	<meta charset="utf-8">
	<script type="text/javascript" src="jquery-3.3.1.js"></script>
</head>
<body>
	<script type="text/javascript">
		$(document).ready(function(){
			$('.p1').hide()
			$('.bt1').click(function(){
				$('.p1').slideDown(777)
			})
			$('.bt2').click(function(){
				$('.p2').slideUp(777)
			})
			$('.bt3').click(function(){
				$('.p3').slideToggle(777)
			})
		})
			
	</script>
	<button class="bt1">下滑</button>
	<p class="p1">With this hand</p>
	<p class="p1">I'll left from sorrows</p>
	<p class="p1">Your cup will never empty</p><br>
	<button class="bt2">上滑</button>
	<p class="p2">You'll be fine</p>
	<p class="p2">Don't worry</p>
	<p class="p2">you will be fine</p><br>
	<button class="bt3">切換</button>
	<p class="p3">For I will be your wine</p>
	<p class="p3">With this candle</p>
	<p class="p3">I'll ligth your darkness</p>
</body>
</html>

     slideUp([speed] [fn]) 通過高度的變化,向上減小的動態(tài)效果 上滑效果

     speed:上滑顯示過程的速度 英文值或者毫秒

     fn:動畫完成時執(zhí)行是函數(shù)


     slideToggle([speed] [fn])通過高度的變化來切換元素的可見性

     speed:上滑隱藏/下滑顯示 過程的速度 英文值或者毫秒

     fn:動畫完成時執(zhí)行是函數(shù)

第三章 jQuery淡入淡出


      jQuery是通過控制不透明度的變化來控制匹配到的元素的淡入淡出效果


      fadeIn([speed] [fn]) 通過不透明度的變化來實(shí)現(xiàn)匹配到元素的淡入的效果;

       fadeOut([speed] [fn])通過不透明度的變化來實(shí)現(xiàn)匹配到元素的淡出的效果;

      fadeToggle([speed] [fn]) 通過不透明度的變化來開關(guān)所有匹配元素的淡入淡出效果;

       fadeTo([speed] opacity [fn]) 把所有匹配到元素的不透明度以漸進(jìn)發(fā)方式調(diào)整到指定的不透明度;

      // speed:規(guī)定效果的時長

      fn:動畫完成時執(zhí)行是函數(shù)

       opacity:fadeTo()方法中必須參數(shù),控制淡入淡出的效果的不透明度(值介于0與1之間)


<!DOCTYPE html>

<html>

<head>

<title>jQuery淡入淡出</title>

<meta charset="utf-8">

<script type="text/javascript" src="jquery-3.3.1.js"></script>

<style type="text/css">

.main{height: 240px;width: 200px;margin-right: 20px;float: left;}

.box1{height: 200px;width: 200px;background: yellowgreen;}

.box2{height: 200px;width: 200px;background: pink;}

.box3{height: 200px;width: 200px;background: blue;}

.box4{height: 200px;width: 200px;background: red;}

button{height: 40px;width: 200px;border:none;}

</style>

</head>

<body>

<script type="text/javascript">

$(document).ready(function(){

$('.box1').hide()

$('.bt1').click(function(){

$('.box1').fadeIn(777)

})

$('.bt2').click(function(){

$('.box2').fadeOut(777)

})

$('.bt3').click(function(){

$('.box3').fadeToggle(777)

})

$('.bt4').click(function(){

$('.box4').fadeTo(777,0.5)

})

})

</script>

<div class="main">

<button class="bt1">淡入</button>

<div class="box1"></div><br>

</div>

<div class="main">

<button class="bt2">淡出</button>

<div class="box2"></div><br>

</div>

<div class="main">

<button class="bt3">切換</button>

<div class="box3"></div><br>

</div>

<div class="main">

<button class="bt4">切換</button>

<div class="box4"></div><br>

</div>

</body>

</html>


第四章 自定義動畫


      jQuery中我們使用 animate()方法創(chuàng)建自定義的動畫


      語法:$(selector).animate({params},speed,fn);


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

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

      可選的 fn是動畫完成后所執(zhí)行的函數(shù)

<!DOCTYPE html>
<html>
<head>
	<title>jQuery自定義動畫</title>
	<meta charset="utf-8">
	<script type="text/javascript" src="jquery-3.3.1.js"></script>
	<style type="text/css">
	div{width: 100px;height: 100px;background: yellowgreen;position: absolute;}
	</style>
</head>
<body>
	<script type="text/javascript">
	$(document).ready(function(){
		$('#bt1').click(function(){
			$('em').animate({fontSize:'37px'},1777)
		})
		$('#bt2').click(function(){
			$('div').animate({
				left:'377',
				opacity:'0.77',
				width:'toggle',
				height:'toggle'
			},1777)
		})
	})
	</script>
	<button id="bt1">點(diǎn)擊字體放大</button><br>

	<em style="color:red">可口可樂</em><br>

	<button id="bt2">點(diǎn)擊移動div</button>
	<div></div>
</body>
</html>

      停止動畫:

      stop() 方法用于停止動畫或效果,在它們完成之前; 該方法適用于所有 jQuery 效果函數(shù),包括滑動、淡入淡出和自定義動畫

      語法:

      $(selector).stop(stopAll,goToEnd)      

      可選的參數(shù) stopAll 規(guī)定是否應(yīng)該清除動畫隊(duì)列。默認(rèn)是 false 僅停止活動的動畫,允許任何排入隊(duì)列的動畫向后執(zhí)行

      可選的參數(shù) goToEnd 規(guī)定是否立即完成當(dāng)前動畫。默認(rèn)是 false

      默認(rèn)情況下 stop() 會清除在被選元素上指定的當(dāng)前動畫

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
	<script type="text/javascript" src="jquery-3.3.1.js"></script>
	<style type="text/css">
	.box1{position: absolute;background-color: pink;}
	</style>
</head>
<body>
	<script type="text/javascript">
	$(document).ready(function(){
		$('#right').click(function(){
			$('.box1').animate({
				left:'600px',
				fontSize:'37px',
				fontWeight:'bold'
			},2777)
		})
		$('#stop').click(function(){
			$('.box1').stop()
		})
	})
	</script>
</body>
<button id="right">右移</button>
<button id="stop">停止</button>
<div class="box1">XXXTENTACION</div>
</html>


Guru membetulkan:韋小寶Masa pembetulan:2019-01-23 11:42:09
Rumusan guru:寫的很棒 總結(jié)注釋的都很清楚 jQuery中可以實(shí)現(xiàn)很多的動畫效果 課后沒事多練習(xí)練習(xí) 繼續(xù)加油吧

Nota Keluaran

Penyertaan Popular