jQuery - 下拉菜单 -

本文介绍了一种使用纯CSS实现的简洁美观的下拉菜单效果,包括选择器、属性等菜单项,并通过jQuery进行交互控制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里写图片描述

<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="author" Content="li">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>菜单列表</title>
    <!-- <link rel="stylesheet" href="css/index.css"> -->
    <style media="screen">
        *{
            margin: 0;
            padding: 0;
            font-family: "Microsoft YaHei", Arial, sans-serif;
            font-size: 14px;
        }
        .list_dt{
            background: #333;
            color: white;
            width: 120px;
            padding: 0 40px 0 20px;
            height: 34px;
            line-height: 34px;
            cursor: pointer;/* 变小手状 */

            overflow: hidden;/* 溢出隐藏 */
            text-overflow: ellipsis;/* 显示省略号 */
            white-space: nowrap;/* 文本不换行 */

            position: relative;
            border-bottom: 1px solid #464646;
        }
        .list_dt:hover{
            background: #222;
        }
        .list_dt:hover ._after{
            display: block;
            width: 3px;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background: #4285F4;
        }
        #open{
            background: #222;
        }
        #open ._after{
            display: block;
            width: 3px;
            height: 100%;
            position: absolute;
            left: 0;
            top: 0;
            background: #4285F4;
        }
        .list_dt_icon{
            position: absolute;
            right: 10px;
            top: 9px;
            display: block;
            width: 16px;
            height: 16px;
            background: url("../images/off.png") no-repeat;
        }
        #open .list_dt_icon{
            background: url("../images/open.png") no-repeat;
        }
        .list_dd{
            display: none;
        }
        .list_li{
            background: #4e4e4e;
            list-style-type: none;
            color: white;
            width: 120px;
            padding: 0 30px;
            height: 34px;
            line-height: 34px;
            cursor: pointer;
            border-bottom: 1px solid #6b6b6b;
        }
        .list_li:hover{
            background: #4285F4;
        }
    </style>
</head>
<body>
    <dl class="list_dl">
        <dt class="list_dt">
            <span class="_after"></span>
            <p>选择器</p>
            <i class="list_dt_icon"></i>
        </dt>
        <dd class="list_dd">
            <ul>
                <li class="list_li">#id</li>
                <li class="list_li">element</li>
                <li class="list_li">.class</li>
                <li class="list_li">*</li>
            </ul>
        </dd>
        <dt class="list_dt">
            <span class="_after"></span>
            <p>属性</p>
            <i class="list_dt_icon"></i>
        </dt>
        <dd class="list_dd">
            <ul>
                <li class="list_li">attr</li>
                <li class="list_li">removeAttr</li>
                <li class="list_li">prop</li>
                <li class="list_li">removeProp</li>
                <li class="list_li">addClass</li>
                <li class="list_li">removeClass</li>
            </ul>
        </dd>
    </dl>
    <!--为了浏览器兼容性jqeury版本推荐使用1.12.0,其他版本会出现不支持某些浏览器-->
   <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.12.4/jquery.js"></script>
   <script type="text/javascript">
    $(".list_dt").on("click",function () {
        $('.list_dd').stop();
        $(this).siblings("dt").removeAttr("id");
        if($(this).attr("id")=="open"){
            $(this).removeAttr("id").siblings("dd").slideUp();
        }else{
            $(this).attr("id","open").next().slideDown().siblings("dd").slideUp();
        }
    });
    </script>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值