jQuery fadeIn() 方法以淡入的效果显示隐藏的元素,用于元素的显示。

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

语法

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

参数

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

例子

<!DOCTYPE html>
<html>
	<title>jQuery fadeIn()方法-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").fadeIn();
        $("#div2").fadeIn("slow");
        $("#div3").fadeIn(3000);
    });
});
</script>
</head>
<body>
<p>查看不同参数的fadeIn()方法示例。</p>
<button>单击以淡入框</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> 
jQuery fadeIn()方法