jQuery fadeOut() 方法以淡出的效果隐藏显示的元素,用于隐藏元素

与之对应的是 fadeIn() 方法以淡入的效果显示隐藏的元素

语法

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

参数

  • speed:可选参数。它指定隐藏元素的速度。它可能的值是slow、normal、fast和毫秒。
  • easing:可选参数指定用于过渡的缓动函数。linear表示匀速移动,swing表示在开头/结尾移动慢,在中间移动快
  • callback:可选参数。回调函数,其中回调函数是在隐藏完成之后执行。

例子

<!DOCTYPE html>
<html>
	<title>jQuery fadeOut()方法-yxjc123.com</title>
<head>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#div1").fadeOut();
        $("#div2").fadeOut("slow");
        $("#div3").fadeOut(3000);
    });
});
</script>
</head>
<body>
<p>查看不同参数的fadeOut()方法示例。</p>
<button>淡出隐藏</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> 

jQuery fadeOut()方法