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

jQuery 效果 - 淡入淡出

jQuery Fading 方法

通過 jQuery,您可以實(shí)現(xiàn)元素的淡入淡出效果。

jQuery 擁有下面四種 fade 方法:

fadeIn()

fadeOut()

fadeToggle()

fadeTo()


fadeIn() 方法

jQuery fadeIn() 用于淡入已隱藏的元素。

語法:

$(selector).fadeIn(speed,callback);

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

可選的 callback 參數(shù)是 fading 完成后所執(zhí)行的函數(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(){
    $("#div1").fadeIn();
    $("#div2").fadeIn("slow");
    $("#div3").fadeIn(4000);
  });
});
</script>
</head>
<body>
<button>點(diǎn)擊淡入</button>
<br><br>
<div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>
</body>
</html>

fadeOut() 方法

jQuery fadeOut() 方法用于淡出可見元素。

語法:

$(selector).fadeOut(speed,callback);

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

可選的 callback 參數(shù)是 fading 完成后所執(zhí)行的函數(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(){
    $("#div1").fadeOut();
    $("#div2").fadeOut("slow");
    $("#div3").fadeOut(5000);
  });
});
</script>
</head>
<body>
<button>點(diǎn)擊淡出</button>
<br><br>
<div id="div1" style="width:80px;height:80px;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>
</body>
</html>

fadeOut() 方法

jQuery fadeOut() 方法用于淡出可見元素。

語法:

$(selector).fadeOut(speed,callback);

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

可選的 callback 參數(shù)是 fading 完成后所執(zhí)行的函數(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(){
    $("#div1").fadeOut();
    $("#div2").fadeOut("slow");
    $("#div3").fadeOut(4000);
  });
});
</script>
</head>
<body>
<button>點(diǎn)擊淡出</button>
<br><br>
<div id="div1" style="width:80px;height:80px;background-color:red;"></div><br>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div><br>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>
</body>
</html>

fadeToggle() 方法

jQuery fadeToggle() 方法可以在 fadeIn() 與 fadeOut() 方法之間進(jìn)行切換。

如果元素已淡出,則 fadeToggle() 會向元素添加淡入效果。

如果元素已淡入,則 fadeToggle() 會向元素添加淡出效果。

語法:

$(selector).fadeToggle(speed,callback);

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

可選的 callback 參數(shù)是 fading 完成后所執(zhí)行的函數(shù)名稱。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("button").click(function(){
    $("#div1").fadeToggle(1000);
    $("#div2").fadeToggle("slow");
    $("#div3").fadeToggle(4000);
    });
});
</script>
</head>
<body>
<button>點(diǎn)擊淡入/淡出</button>
<br><br>
<div id="div1" style="width:80px;height:80px;background-color:red;"></div>
<br>
<div id="div2" style="width:80px;height:80px;background-color:green;"></div>
<br>
<div id="div3" style="width:80px;height:80px;background-color:blue;"></div>
</body>
</html>


繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <style type="text/css"> .big{ font-size:30px; color:#FF0000;} </style> </head> <body> <script> function fadeIn(){ $("#popup").fadeIn(2000); $("#popup").css("position","absolute"); $("#popup").css("left","100px"); $("#popup").css("top","100px"); } function fadeOut(){ $("#popup").fadeOut(2000); } function fadeTo(){ $("#popup").fadeTo(2000,0.5); } </script> <input type="button" value="彈出層" onclick="fadeIn()" > <div id="popup" style="width:200px;height:200px;border:1px red solid;display:none;background-color:red;"> 彈出層的試驗(yàn) <br> <input type="button" value="取消" onclick="fadeOut()" > <input type="button" value="半透明" onclick="fadeTo()" > </div> </body> </html>
提交重置代碼