jquery实现点击按钮显示与隐藏效果

首先来看实现效果
在这里插入图片描述
用jquery来实现这种效果是非常简单的

html

<div class="bottom">
            <ul>
                <li class="active">
                    <span class="iconfont icon-yemian-copy-copy"></span>
                    <p>首页</p>
                </li>
                <li>
                    <span class="iconfont icon-caidan"></span>
                    <p>热卖</p>
                </li>
                <li>
                    <span class="iconfont icon-gouwuche"></span>
                    <p>购物车</p>
                </li>
                <li>
                    <span class="iconfont icon-my"></span>
                    <p>我的</p>
                </li>
            </ul>
        </div>

css

<style>
 		html,
        body,
        div,
        ul,
        li,
        img,
        p {
            margin: 0;
            padding: 0;
        }

        body {
            width: 100%;
        }

        ul {
            list-style: none;
        }
        .bottom {
            border-top: 1px lightgray solid;
        }

        .bottom ul {
            height: 50px;
            display: flex;
            justify-content: space-around;
            align-items: center;

        }

        .bottom ul li {
            text-align: center;
        }

        .bottom li span {
            font-size: 26px;
            font-weight: bold;
        }

        .bottom li p {
            font-size: 18px;
        }

        .bottom li.active {
            color: crimson;
        }

        .bottom li:hover {
            cursor: pointer;
        }
    </style>

js

    <script>
        function tab() {
            $('.bottom li').on('click', function (e) {
                $(this).addClass("active").siblings().removeClass("active");
            })
        }
        tab();  
    </script>

记得引用iconfont和jquery

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值