CSS Transitions and transforms on SVG elements

后端 未结 1 1289
闹比i
闹比i 2021-01-13 07:34

I am currently trying to rotate an SVG group using a CSS transform and animate it using CSS transitions. I am getting the desired transform but not the animate, any idea on

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 08:32

    Fixed it!

    The transition was in the wrong place, I had assumed that the transition would descend down to the children elements but apparently not. Also fixed the rotation by animating between 0 and 180 degrees.

    Inline SVG

    
        
            
                
                
                
                
                
                
                
                
            
        
    
    

    Compass SCSS

    .hub-icon-container {
        &:hover {
            .hub-icon {
                transform:rotate(180deg);
                -ms-transform:rotate(180deg);
                -webkit-transform:rotate(180deg);
            }
        }
        .hub-icon {
            @include transition(all 0.5s ease-in-out);
            transform:rotate(0deg);
            transform-origin:50% 50%;
            -ms-transform:rotate(0deg);
            -ms-transform-origin:50% 50%;
            -webkit-transform:rotate(0deg);
            -webkit-transform-origin:50% 50%;
        }
    }
    

    Compiled CSS

    .hub-icon-container:hover .hub-icon {
      transform: rotate(180deg);
      -ms-transform: rotate(180deg);
      -webkit-transform: rotate(180deg);
    }
    .hub-icon-container .hub-icon {
      -webkit-transition: all 0.5s ease-in-out;
      -moz-transition: all 0.5s ease-in-out;
      -o-transition: all 0.5s ease-in-out;
      transition: all 0.5s ease-in-out;
      transform: rotate(0deg);
      transform-origin: 50% 50%;
      -ms-transform: rotate(0deg);
      -ms-transform-origin: 50% 50%;
      -webkit-transform: rotate(0deg);
      -webkit-transform-origin: 50% 50%;
    }
    

    CodePen Updated below

    http://codepen.io/alexbaulch/pen/bDkhv

    0 讨论(0)
提交回复
热议问题