html:
<div class="knowledge-left fl"> <div class="menu-item down"> <a href="javascript:;" class="sub-title">买房准备</a> <ul> <li> <a href="" class="actived">购房资格</a> <a href="">购房能力</a> </li> <li> <a href="">购房政策</a> <a href="">交易流程</a> </li> </ul> </div> <div class="menu-item right"> <a href="javascript:;" class="sub-title">看房选房</a> <ul> <li> <a href="">选新房技巧</a> <a href="">选二手房技巧</a> </li> <li> <a href="">选教育地产技巧</a> <a href="">建筑类型</a> </li> </ul> </div> </div>
js:
<script> $(document).ready(function () { $(‘.menu-item .sub-title‘).each(function (index) { $(this).click(function () { let _this = $(this); let _parent = _this.parent(); let _siblings = _this.siblings(‘ul‘); if (_parent.hasClass(‘down‘)) { _parent.removeClass(‘down‘); _parent.addClass(‘right‘); _siblings.hide(); } else { _parent.removeClass(‘right‘); _parent.addClass(‘down‘); _siblings.show(); } }) }) }); </script>
css:
.knowledge-left .menu-item { margin-top: 20px; } .knowledge-left .menu-item .sub-title { padding-left: 16px; font-size: 16px; font-weight: bold; color: #333; } .knowledge-left .menu-item.down .sub-title { background: url("//static.fczx.com/www/assets/icons/triangle-down.png") no-repeat left center; } .knowledge-left .menu-item.right .sub-title { background: url("//static.fczx.com/www/assets/icons/triangle-right.png") no-repeat left center; } .knowledge-left .menu-item.right ul { display: none; } .knowledge-left .menu-item ul { padding-left: 16px; margin-top: 15px; } .knowledge-left .menu-item ul>li>a { display: inline-block; min-width: 140px; font: 14px/30px "Miscrosoft Yahei"; color: #666; } .knowledge-left .menu-item ul>li>a:hover { color: #df2f30; } .knowledge-left .menu-item ul>li>a.actived { color: #df2f30; font-weight: bold; }