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

Leona ·
更新时间:2024-09-20
· 1480 次阅读

本文实例为大家分享了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



jQuery 按钮

需要 登录 后方可回复, 如果你还没有账号请 注册新账号