Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Keyframe animation of SVG not working in safari, works in chrome.

I am animating an SVG of a car and I'm trying to get the 'car body' to bounce. It works perfectly in Chrome but I cant figure out Safari (& possibly other growers which I havnt tested yet)

#car-body{
     -webkit-animation-name: carbody;
     -webkit-animation-duration: .5s;
     -webkit-animation-iteration-count: infinite;
     animation-name: carbody;
      animation-duration: .5s;
      animation-iteration-count: infinite;
      transform-origin: 50% 50%;
      display: inline-block;
      webkit-ANIMATION-timing-function: linear;
  }

  @keyframes carbody {
      0% {transform: translateY(0px); }
      60% {transform: translateY(-4px);}
      80% { transform: translateY(1px);}
  }

@-webkit-keyframes carbody {
      0% {bottom: 30px;}
      60% {bottom: 35px;}
      80% {bottom: 37px;}
  }


FIXED CODE - That works, thanks to answer below.

#car-body{

     -webkit-animation-name: car-body;
     -webkit-animation-duration: .5s;
     -webkit-animation-iteration-count: infinite;
        animation-name: car-body;

      animation-duration: .5s;
      /* Things added */
      animation-iteration-count: infinite;
      transform-origin: 50% 50%;
      display: inline-block;
         webkit-ANIMATION-timing-function: linear;
  }

  @-webkit-keyframes car-body {
      0% {
          bottom: 30px;
      }
      60% {
          bottom: 35px;
      }
      80% {
          bottom: 37px;
      }
  }

  @keyframes car-body {
      0% {
          transform: translateY(0px);
      }
      60% {
          transform: translateY(-4px);
      }
      80% {
          transform: translateY(1px);
      }
  }



          ```

1 Answer

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hi cleo inacio,

Safari is applying the @-webkit-keyframes carbody rule to #car-body. That rule uses bottom offsets in the animation sequence vs. the transforms applied in the unprefixed @keyframes rule. Change the @-webkit-keyframes carbody to transforms, and be sure to place the @-webkit-keyframes above the unprefixed rule. :)

Thank you! :) - The changes worked!