jQuery实现淡入淡出效果

2022-07-22,,,

用jquery完成淡入淡出效果前,我们先来认识几个代码:

  • 淡入 fadein([ speed , [easing] , [fn] ]),参数都可不写
  • 淡出 fadeout([ speed , [easing] , [fn] ]),参数都可不写
  • 淡入淡出切换 fadetoggle([ speed , [easing] , [fn] ]),参数都可不写
  • 修改透明度 fadeto([ [speed] , opacity , [easing] , [fn] ]),注意,这里速度和透明度一定要写

其中

  • speed是速度
  • easing是切换效果
  • fn是回调函数

那我们把上述代码放到整体代码中看下效果

完整代码如下

<!doctype html>
<html lang="en">
 
<head>
    <meta charset="utf-8">
    <title>wellfancy</title>
    <style>
        div {
   margin: 10px;
   padding: 10px;
   width: 100px;
            display: none;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
 
<body>
    <button>淡入效果</button>
    <button>淡出效果</button>
    <button>淡入淡出切换</button>
    <button>修改透明度</button>
    <div>
  <img src="images/1.jpg" style="width: 280px;">
 </div>
    <script>
        $(function() {
            $("button").eq(0).click(function() {
                $("div").fadein(1000);
            })
            $("button").eq(1).click(function() {
                $("div").fadeout(1000);
 
            })
            $("button").eq(2).click(function() {
                $("div").fadetoggle(1000);
 
            });
            $("button").eq(3).click(function() {
                $("div").fadeto(1000, 0.5);
 
            });
 
        });
    </script>
</body>
 
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

《jQuery实现淡入淡出效果.doc》

下载本文的Word格式文档,以方便收藏与打印。