下拉菜单案例(children+this)

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            list-style: none;
        }

        .wrap {
            width: 330px;
            height: 30px;
            margin: 100px auto 0;
            padding-left: 10px;
            background-image: url(imgs/bg.jpg);
        }

        .wrap li{
            background-image: url(imgs/libg.jpg);
        }

        .wrap > ul > li {
            float: left;
            margin-right: 10px;
            position: relative;
        }

        .wrap a {
            display: block;
            height: 30px;
            width: 100px;
            text-decoration: none;
            color: #000;
            line-height: 30px;
            text-align: center;
        }

        .wrap li ul {
            position: absolute;
            top: 30px;
            display: none;
        }
    </style>
    <script src="js/jquery-1.11.1.min.js"></script>
    <script>
        $(document).ready(function () {
            var jqli=$(".wrap>ul>li");
            jqli.mouseenter(function () {
                $(this).children("ul").show();
               /* this.children(1).style.display="block";*/
            });
            jqli.mouseleave(function () {
                $(this).children("ul").hide();
                /*this.children(1).style.display="none";*/
            });
        });
    </script>
</head>
<body>
    <div class="wrap">
        <ul>
            <li>
                <a href="javascript:void(0);">一级菜单1</a>
                <ul>
                    <li href="javascript:void(0)">二级菜单1</li>
                    <li href="javascript:void(0)">二级菜单2</li>
                    <li href="javascript:void(0)">二级菜单3</li>
                </ul>
            </li>

            <li>
                <a href="javascript:void(0);">一级菜单2</a>
                <ul>
                    <li href="javascript:void(0)">二级菜单1</li>
                    <li href="javascript:void(0)">二级菜单2</li>
                    <li href="javascript:void(0)">二级菜单3</li>
                </ul>
            </li>

            <li>
                <a href="javascript:void(0);">一级菜单3</a>
                <ul>
                    <li href="javascript:void(0)">二级菜单1</li>
                    <li href="javascript:void(0)">二级菜单2</li>
                    <li href="javascript:void(0)">二级菜单3</li>
                </ul>
            </li>
        </ul>
    </div>
</body>
</html>

缓慢下拉

 <script>
        $(document).ready(function () {
            var jqli=$(".wrap>ul>li");
            jqli.mouseenter(function () {
               $(this).children("ul").stop().slideDown(1000);
            });
            jqli.mouseleave(function () {
                $(this).children("ul").stop().slideUp(1000);
            });
        });
    </script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值