jQuery-slideDown向下滑,slideUp向上滑,slideToggle滑动

1.基本概念

  • slideDown() 向下滑动,显示
  • slideUp() 向上滑动,隐藏
  • slideToggle() 滑动切换

2.代码如下

滑动展示

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>滑动动画</title>
    <style>
        #box {
            width: 300px;
            height: 200px;
            border: 1px solid #000;
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <button id="show">显示</button>
    <button id="hide">隐藏</button>
    <button id="toggle">切换</button>
    <div id="box">文字</div>
    <script src=" https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
    <script>
        $("#show").click(function() {
            $("#box").slideDown(1500)
        })
        $("#hide").click(function() {
            $("#box").slideUp(1500)
        })
        $("#toggle").click(function() {
            $("#box").slideToggle(1500)
        })
    </script>
</body>

</html>

滑动应用

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>滑动导航</title>
    <style>
        ul {
            list-style: none;
        }
        
        li {
            width: 240px;
            font-size: 14px;
            padding: 15px 20px;
        }
        
        li:hover {
            background-color: #ecf5ff;
        }
        
        #subNav {
            display: none;
            width: 200px;
        }
    </style>
</head>


<body>
    <div id="nav">
        <ul class="list">
            <li>导航1
                <ul class="subNav">
                    <li>选项1</li>
                    <li>选项2</li>
                </ul>
            </li>
            <li>导航2
                <ul class="subNav">
                    <li>选项1</li>
                    <li>选项2</li>
                </ul>
            </li>
            <li>导航3
                <ul class="subNav">
                    <li>选项1</li>
                    <li>选项2</li>
                </ul>
            </li>
        </ul>
    </div>
</body>
<script src=" https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
<script>
    $(".list>li").click(function() {
        $(this).find('.subNav').slideToggle()
    })
</script>

</html>

滑动应用

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>从底部显示文字</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #box {
            width: 200px;
            height: 240px;
            border: 1px solid #000;
            position: relative;
            margin: 0 auto;
        }
        
        .bottomShow {
            border: 1px solid red;
            position: absolute;
            bottom: 0px;
            left: 0px;
            display: none;
        }
    </style>
</head>

<body>
    <div id="box">
        <p>产品</p>
        <p class="bottomShow">我爱你</p>
    </div>
    <script src=" https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
    <script>
        $("#box").mouseover(function() {
            $(".bottomShow").slideDown(1000)
        })
        $("#box").mouseout(function() {
            $(".bottomShow").slideUp()
        })
    </script>
</body>

</html>
posted @ 2020-05-21 21:14  东血  阅读(445)  评论(0编辑  收藏  举报

载入天数...载入时分秒...