jQuery學習筆記之jQuery動畫效果
基本動畫代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World jQuery!</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//基本的動畫函數(shù)主要分為show, hide和toggle三個. 都提供了無參數(shù)的版本
//并且都提供了兩個參數(shù)的重載,如show( speed, [callback] ),
//callback,簽名如下:function callback() {this;}在回調(diào)函數(shù)中的this 是執(zhí)行此函數(shù)的DOM 對象. 會在動畫結(jié)束時執(zhí)行.
//因為回調(diào)函數(shù)可以省略, 所以可以傳入一個數(shù)值作為唯一參數(shù), 則會在參數(shù)規(guī)定的時間內(nèi)用動畫效果的顯示/隱藏元素
//參數(shù)可以使用三種預定速度之一的字符串("slow", "normal", "fast")
//或直接使用數(shù)字表示動畫時長,單位是毫秒數(shù)值(如500).
//動畫速度
var speed = 500;
//綁定事件處理
$("#btnShow").click(function(event)
{
//取消事件冒泡
event.stopPropagation();
//設(shè)置彈出層位置
var offset = $(event.target).offset();
$("#divPop").css({ top: offset.top + $(event.target).height()+ "px", left: offset.left });
//動畫顯示
$("#divPop").show(speed);
});
//單擊空白區(qū)域隱藏彈出層
$(document).click(function(event) { $("#divPop").hide(speed) });
//單擊彈出層則自身隱藏
$("#divPop").click(function(event) {
event.stopPropagation()
$("#divPop").hide(speed);
});
var flip = 0;
$("#btnP").click(function () {
$("p").toggle("fast");
//$("p").toggle( flip++ % 2 == 0 );
});
//綁定事件處理
$("#btnT").click(function(event)
{
//取消事件冒泡
event.stopPropagation();
//設(shè)置彈出層位置
var offset = $(event.target).offset();
$("#divPop").css({ top: offset.top + $(event.target).height() + "px", left: offset.left });
//切換彈出層的顯示狀態(tài)
$("#divPop").toggle(speed);
});
});
</script>
</head>
<body>
<div>
<br /><br /><br />
<button id="btnShow">顯示提示文字</button>
<button id=btnP>顯示段落</button>
<button id=btnT>toggle函數(shù)測試</button>
</div>
<!-- 彈出層-->
<div id="divPop" style="background-color: #f0f0f0; border: solid 1px
#000000; position: absolute; display:none;
width: 600px; height: 100px;">
<div style="text-align: center;">彈出層</div>
</div>
<p>這個是一個段落</p>
<p>這個是第二個段落</p>
</body>
</html>
============================================================
滑動動畫和透明動畫效果代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello World jQuery!</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
//滑動動畫效果
$("#btnShow").click(function(){
$("#divPop").slideDown("fast");
});
$("#btnHide").click(function(){
$("#divPop").slideUp("slow");
});
$("#btnT").click(function(){
$("#divPop").slideToggle("slow");
});
//透明度動畫效果
$("#bShow").click(function(){
$("#divPop").fadeIn(2000);
});
$("#bHide").click(function(){
$("#divPop").fadeOut("slow");
});
//指定到透明度
$("#bHelf").click(function(){
$("#divPop").fadeTo("slow",0.3);
});
});
</script>
</head>
<body>
<div>
<br /><br /><br />
<button id="btnShow">顯示提示文字</button>
<button id="btnHide">隱藏提示文字</button>
<button id=btnT>toggle函數(shù)測試</button>
<br />
<button id=bShow>淡入</button>
<button id=bHide>淡出</button>
<button id=bHelf>半透明</button>
</div>
<!-- 彈出層-->
<div id="divPop" style="background-color: #f0f0f0; border: solid 1px
#000000; position: absolute; display:none;
width: 600px; height: 100px;">
<div style="text-align: center;">彈出層</div>
</div>
<p>這個是一個段落</p>
<p>這個是第二個段落</p>
</body>
</html>
相關(guān)文章
jqGrid日期格式的判斷示例代碼(開始日期與結(jié)束日期)
jqGrid日期格式的判斷示例代碼(開始日期與結(jié)束日期)。需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11jQuery增加、刪除及修改select option的方法
這篇文章主要介紹了jQuery增加、刪除及修改select option的方法,涉及jQuery針對form表單中select選項的常見操作技巧,需要的朋友可以參考下2016-08-08Jquery遍歷篩選數(shù)組的幾種方法和遍歷解析json對象,Map()方法詳解以及數(shù)組中查詢某值是否存在
今天小編就為大家分享一篇關(guān)于Jquery遍歷篩選數(shù)組的幾種方法和遍歷解析json對象|Map()方法詳解以及數(shù)組中查詢某值是否存在,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01jQuery EasyUI API 中文文檔 - ComboTree組合樹
jQuery EasyUI API 中文文檔 - ComboTree組合樹,需要的朋友可以參考下。2011-10-10Jquery EasyUI的添加,修改,刪除,查詢等基本操作介紹
初識Jquery EasyUI看了一些博主用其開發(fā)出來的項目,頁面很炫,感覺功能挺強大,效果也挺不錯,最近一直想系統(tǒng)學習一套前臺控件,于是在網(wǎng)上找了一些參考示例2013-10-10jQuery源碼解讀之extend()與工具方法、實例方法詳解
這篇文章主要介紹了jQuery源碼解讀之extend()與工具方法、實例方法,分析了jQuery中extend()源碼、功能與相關(guān)使用技巧,需要的朋友可以參考下2017-03-03