DIV CSS 佈局教程網

用 jQuery 的 fadeOut 實現元素漸隱效果
編輯:JQuery特效代碼     

本文示範如何使用 jQuery 的 fadeOut() 方法,讓元素逐漸淡出(漸隱)消失,並可控制隱藏速度。

<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").fadeOut();          // 預設速度
    $("#div2").fadeOut("slow");  // 慢速
    $("#div3").fadeOut(3000);    // 3000 毫秒
  });
});
</script>
</head>
<body>
<p>Demonstrate fadeOut() with different parameters.</p>
<button>Click to fade out boxes</button>
<br><br>
<div id="div1" style="width:80px;height:80px;background-color:red;"></div>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>
</body>
</html>

這裡對三個色塊分別套用不同參數,可明顯看出速度差異:不帶參數為預設、"slow" 為慢速、數字則以毫秒計。fadeOut() 完成後元素會被設為 display:none。希望本文對大家的 jQuery 開發有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved