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

鼠标离开时悬停动画抖动(使用CSS转换和变换)

  •  0
  • catandmouse  · 技术社区  · 6 年前

    <svg viewBox="-5 -5 50 50">
        <circle cx="20" cy="20" r="20" />
        <path d="M20,31 C15.4189994,27.2225585 12.5023327,24.2225585 11.25,22 C10.2743515,20.6156479 10,19.6181623 10,18.1428571 C10,15.5113854 12.4883456,13 15,13 C17.3176009,13 18.9621484,13.8491346 20,15.5714286 C21.0382977,13.8491346 22.6828452,13 25,13 C27.5116544,13 30,15.5113854 30,18.1428571 C30,19.6181623 29.7256485,20.6156479 28.75,22 C27.497816,24.2225585 24.5811493,27.2225585 20,31 Z" />
    

    circle {
        fill: #EEE;
        -webkit-transition: -webkit-transform .1s ease-in-out; 
        -moz-transition: -moz-transform .1s ease-in-out; 
    }
    
    path {
        fill: #CCC;
    }
    
    svg:hover circle {
        transform: scale(1.15);
        -ms-transform: scale(1.15);
        -webkit-transform: scale(1.15);
        transform-origin: center center;
        -webkit-transform-origin: center center;
        -ms-transform-origin: center center;
    }
    

    https://codepen.io/aguerrero/pen/EeXJRx

    1 回复  |  直到 6 年前
        1
  •  2
  •   VXp Kadir BuÅ¡atlić    6 年前

    移动 transform-origin 属性 内部的一般规则 circle 要素 :hover :

    circle {
      fill: #EEE;
      -webkit-transition: -webkit-transform .1s ease-in-out; 
      -moz-transition: -moz-transform .1s ease-in-out;
      transform-origin: center center;
      -webkit-transform-origin: center center;
      -ms-transform-origin: center center;
    }
    
    path {
      fill: #CCC;
    }
    
    svg:hover circle {
      transform: scale(1.15);
      -ms-transform: scale(1.15);
      -webkit-transform: scale(1.15);
    }
    <svg viewBox="-5 -5 50 50">
      <circle cx="20" cy="20" r="20" />
      <path d="M20,31 C15.4189994,27.2225585 12.5023327,24.2225585 11.25,22 C10.2743515,20.6156479 10,19.6181623 10,18.1428571 C10,15.5113854 12.4883456,13 15,13 C17.3176009,13 18.9621484,13.8491346 20,15.5714286 C21.0382977,13.8491346 22.6828452,13 25,13 C27.5116544,13 30,15.5113854 30,18.1428571 C30,19.6181623 29.7256485,20.6156479 28.75,22 C27.497816,24.2225585 24.5811493,27.2225585 20,31 Z" />
    </svg>