右侧弹窗tab切换以及向左展开,向右收起的实现方法

我要实现的效果是将一个弹窗像左展开向右收起,实现方法如下:
DOM层代码:

 <div class="unfold-away-wrap">
        <div class="unfold-away-btn"></div>
        <ul class="tab-wrap">
            <li class="tab-active">
                <span>内容一</span>
            </li>
            <li>
                <span>内容二</span>
            </li>
        </ul>
        <div class="tab-con">
            <div class="con">内容一</div>
            <div class="con" style="display:none">内容二</div>
        </div>
    </div>

在dom层布局的时候一定注意,只需给最外层的div给一个绝对定位,然后三个按钮相对于最外层的父级盒子进行绝对定位,tab-con里面的内容能不用定位就不要用定位。
css代码:

.unfold-away-wrap{
    width: 200px;
    height: 350px;
    position:absolute;
    top: 50px;
    right: 10px;
    background:#1890ff;
    padding: 10px;
    box-sizing: border-box;
    border-radius: 4px;
    .unfold-away-btn{
        width: 14px;
        height: 50px;
        background:url("../img/unflod-icon.png") no-repeat;
        border-radius: 4px;
        position: absolute;
        top: 160px;
        left: -13px;
        cursor: pointer;
    }
    .unfoldBtn{
    width: 14px;
    height: 50px;
    background:url("../img/unfold-icon.png") no-repeat;
    background-size: 100% 100%;
    position:absolute;
    top:160px;
    left:-13px;
    cursor: pointer;
  }
 .tab-wrap{
     font-size: 0;
     position: absolute;
     top: 10px;
     left: -18px;
     cursor: pointer;
     li{
      width: 19px;
      background:url("../img/tab-label-bg.png") no-repeat;
      background-size:100% 100%;
      text-align:center;
      padding: 10px 0;
      span{
        font-size: 12px;
        font-family: SourceHanSansCN-Regular, SourceHanSansCN;
        font-weight: 400;
        color: #333333;
        line-height: 18px;
      }
    }
     .tab-active{
      width: 19px;
      background:url("../img/tab-active-bg.png") no-repeat;
      background-size:100% 100%;
      text-align:center;
      padding: 10px 0;
      span{
        font-size: 12px;
        font-family: SourceHanSansCN-Bold, SourceHanSansCN;
        font-weight: bold;
        color: #FFFFFF;
        line-height: 18px;
        text-shadow: 0px 1px 3px rgba(5, 87, 127, 0.5);
      }
    }
 }
 }

js操作dom层实现tab切换和弹窗的展开收起

 $(function () {
 // 切换弹窗内容
 $('.tab-wrap li').click(function () {
  var index = $(this).index()
  $(this).addClass('tab-active').siblings().removeClass('tab-active')        $(this).parent().next().children().eq(index).show().siblings().hide()
  });
   // 右侧弹窗展开收起
    const zh = false // 先将其定义为false,经过取反之后成为true,也就是默认为展开状态
    $('.unfold-away-btn').click(function () {
     this.zh = !this.zh
     if (this.zh === true) {
     $('.unfold-away-wrap').animate({ right: '10px' }, 350)
      $(this).removeClass('unfoldBtn')
      } else {
      $('.unfold-away-wrap').animate({ right: '-200px' }, 350)
      $(this).addClass('unfoldBtn')
            }
        });
    })

实现效果如下:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值