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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

coder_wb   2022-05-28 我要评论

首先来看实现效果

用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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们