jQuery特效 fadeOut()方法

jQuery特效 fadeOut()方法

jQuery中的fadeOut()方法是用来改变选定元素的不透明度水平,从可见到隐藏。通过使用这个方法,褪色的元素将不占用任何空间。

语法:

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

参数:该方法接受上面提到的和下面描述的三个参数。

  • speed:这是一个可选参数,用于指定渐变效果的速度。速度的默认值是400毫秒。速度的可能值是。
    • milliseconds
    • “slow”
    • “fast”
  • easing。这是一个可选的参数,用于指定元素到不同动画点的速度。缓和的默认值是 “摆动”。缓和的可能值是。
    • “swing”
    • “linear”
  • callback。它是可选参数。该回调函数在fadeOut()方法完成后执行。

例子1:这个例子显示淡入和淡出效果。

<!DOCTYPE html>
<html>
  
<head>
    <title>
        jQuery | fadeOut() Method
    </title>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    </script>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>jQuery | fadeOut() Method</h2>
    <button class="btn1">Fade out</button>
    <button class="btn2">Fade in</button>
  
    <!-- Script to display fadeIn and fadeOut effect -->
    <script>
        (document).ready(function () {
            (".btn1").click(function () {
                ("h2").fadeOut()
            });
  
            (".btn2").click(function () {
                $("h2").fadeIn();
            });
        });
    </script>
</body>
  
</html>

输出:

jQuery特效 fadeOut()方法

实例2:本例创建淡入淡出效果并设置其速度。给定的速度以毫秒为单位。

<!DOCTYPE html>
<html>
  
<head>
    <title>
        jQuery | fadeOut() Method
    </title>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>jQuery | fadeOut() Method</h2>
    <button class="btn1">Fade out</button>
    <button class="btn2">Fade in</button>
  
    <script>
        (document).ready(function () {
            (".btn1").click(function () {
                ("h2").fadeOut(1000);
            });
  
            (".btn2").click(function () {
                $("h2").fadeIn(1000);
            });
        });
    </script>
</body>
  
</html>

输出:

jQuery特效 fadeOut()方法

示例3:创建带有警报信息的淡入和淡出效果。

<!DOCTYPE html>
<html>
  
<head>
    <title>
        jQuery | fadeOut() Method
    </title>
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    </script>
</head>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>jQuery | fadeOut() Method</h2>
    <button class="btn1">Fade out</button>
    <button class="btn2">Fade in</button>
  
    <!-- Script to create fadeIn and fadeOut effect -->
    <script>
        (document).ready(function () {
            (".btn1").click(function () {
                ("h2").fadeOut(1000, function () {
                    alert("fadeOut() method is finished!");
                });
            });
  
            (".btn2").click(function () {
                $("h2").fadeIn(1000, function () {
                    alert("fadeIn() method is finished!");
                });
            });
        });
    </script>
</body>
  
</html>

输出:

jQuery特效淡出()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程