rotate(180deg) 旋转过程父元素高度压缩

如图所示

点击按钮,icon rotate 过程中父元素高度压缩导致子元素被遮挡
在这里插入图片描述

原因

rotate 过程父元素重绘导致高度发生变化

解决方案

给父元素加 overflow:hidden; 如果rotate过程元素内容模糊,可在发生动画的元素加 translate3d(0, 0, 0);

原代码

html
<div class="comm-box">
    <div class="head">
      <div class="comm-title">{{ title }}</div>
      <div class="right" @click="onChange">
        <div class="label">{{ show ? '收起' : '展开' }}</div>
        <van-icon
          :class="show ? 'icon-rotate' : ''"
          class="icon"
          name="arrow-down"
        />
      </div>
    </div>
    <div :style="{ maxHeight: show ? '2000px' : '0' }" class="html-content">
      <div v-show="show" v-dompurify-html="content" class="html"></div>
    </div>
  </div>
  css
  .comm-box {
  min-height: 20px;
  padding: 16px 16px 16px 0;
  border-radius: 16px;
  margin: 8px 16px 10px;
  background: #ffffff;
  overflow: hidden;
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;

  .comm-title {
    height: auto;
    padding: 0 0 0 16px;
    color: #333333;
    font-size: 18px;
    line-height: 24px;
    font-weight: 700;
    position: relative;

    &:after {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      width: 6px;
      height: 24px;
      background: #2e80fe;
      border-radius: 0 10px 10px 0;
    }
  }

  .right {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: #999999;
    width: 60px;
    height: 22px;

    .label {
      margin-right: 8px;
    }
  }

  .icon {
    transition: 0.5s;
    transform: translate3d(0, 0, 0);
  }

  .icon-rotate {
    transform: rotateZ(180deg) translate3d(0, 0, 0);
  }
}

.html-content {
  transition: 0.5s;

  .html {
    padding: 12px 0 0 16px;
    font-size: 14px;
    color: #333333;
    line-height: 22px;
  }
}

修改后代码

css
.comm-box {
  min-height: 20px;
  padding: 16px 16px 16px 0;
  border-radius: 16px;
  margin: 8px 16px 10px;
  background: #ffffff;
  overflow: hidden;
}

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;

  .comm-title {
    height: auto;
    padding: 0 0 0 16px;
    color: #333333;
    font-size: 18px;
    line-height: 24px;
    font-weight: 700;
    position: relative;

    &:after {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      width: 6px;
      height: 24px;
      background: #2e80fe;
      border-radius: 0 10px 10px 0;
    }
  }

  .right {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    color: #999999;
    width: 60px;
    height: inherit;
    overflow: hidden;

    .label {
      margin-right: 8px;
    }
  }

  .icon {
    transition: 0.5s;
    transform: translate3d(0, 0, 0);
  }

  .icon-rotate {
    transform: rotateZ(180deg) translate3d(0, 0, 0);
  }
}

.html-content {
  transition: 0.5s;

  .html {
    padding: 12px 0 0 16px;
    font-size: 14px;
    color: #333333;
    line-height: 22px;
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值