代码之家  ›  专栏  ›  技术社区  ›  cosmichero2025

当我使用过渡/动画增大大小时,子元素会“抖动”

css
  •  2
  • cosmichero2025  · 技术社区  · 7 年前

    我在这里有一个圆圈,当我悬停在它上面时,它会随着大小而增大。当我这么做的时候,中间的“+”会震动。

    HTML格式

        <div class='test-ani'>
           <span>+</span>
        </div>
    

    .test-ani {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100px;
        height: 100px;
        border-radius: 50%;
        background-color: cornflowerblue;
        user-select: none;
        cursor: pointer;
    
        &:hover {
            transition: .5s;
            width: 120px;
            height: 120px;
        }
    
        span {
            color: #ffdb58;
            font-size: 50px;
            padding: 0;
            margin: 0;
        }
    }
    

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  1
  •   Piterden    7 年前

    动画转换规则:

    section {
      position: relative;
      width: 100%;
      height: 100%;
    }
    .test-ani {
      position: absolute;
      top: 50%;
      left: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100px;
      height: 100px;
      border-radius: 50%;
      background-color: cornflowerblue;
      user-select: none;
      cursor: pointer;
    }
    .test-ani:hover {
      transition: transform .5s;
      transform: scale(1.2);
    }
    .test-ani span {
      color: #ffdb58;
      font-size: 50px;
      padding: 0;
      margin: 0;
    }
    <section>
      <div class='test-ani'>
         <span>+</span>
      </div>
    </section>