27

I have applied -webkit-transform:rotateY(180deg); to flip an image. I am applying -webkit-transform:rotateY(0deg); to rotate it back to original position. Now I have some other classes to be applied, but when I check in Chrome Inspect Element I can see that rotateY(0) is still there which should be completely removed.

How can I remove the animation completely from an Element?

.transition
{
  -webkit-transform:rotateY(180deg);
  transform:rotateY(180deg);
}

.notransition {
  -webkit-transform:rotateY(0deg);
  transform:rotateY(0deg);
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
anam
  • 3,905
  • 16
  • 45
  • 85

3 Answers3

49

just do this:

.transition {
  -webkit-transform: rotateY(180deg);
  transform: rotateY(180deg);
}

.notransition {
  -webkit-transform: none;
  transform: none;
}

none seems to be the default value

Mark
  • 6,762
  • 1
  • 33
  • 50
  • But what if I added both rotation and translation and would like to remove only one of them? E.g. I want to remove only rotation. Should I compute the undo value for the rotation and apply it in css then or is there a different way to achieve this? – hellouworld Feb 25 '20 at 10:49
  • 2
    transform accepts comma separated values, the order you specify both properties, is also the order you disable the properties. `.transition { transform: rotateY(180deg), rotateX(180deg); }` `.notransition { transform: none, rotateX(180deg); }` – Mark Feb 26 '20 at 13:17
  • Very important and useful. Thank you. Could you, please, provide a source which taught you this? – hellouworld Feb 26 '20 at 13:41
  • 1
    I correct my previous comment, it's not comma separated, it's space separated, background properties are comma separated. More info: here you go: https://developer.mozilla.org/en-US/docs/Web/CSS/transform – Mark Feb 26 '20 at 15:46
9
.transition {
    -webkit-transform:rotateY(180deg);
    transform:rotateY(180deg);
}

.notransition {
    -webkit-transform:unset;
    transform:unset;
}
Mark
  • 6,762
  • 1
  • 33
  • 50
1

In my case i needed a way to override an inline transform that was being setted by third party component and i didn't want it to remove it manually.

According to Mozilla documentation, you can only transform elements:

Only transformable elements can be transformed. That is, all elements whose layout is governed by the CSS box model except for: non-replaced inline boxes, table-column boxes, and table-column-group boxes.

So, you can disable transform by just modifing display to a non-element one, I changed it to display:inline so the transform stops working:

.transition {
    -webkit-transform:rotateY(180deg);
    transform:rotateY(180deg);
}
    
.notransition {
    display: inline;
}

Of course this will mess up with animation, however it's usefull when you are working with responsive CSS:

// small resolution / animation will stop working, and element will expand to the whole screen
.transition {
    -webkit-transform:rotateY(180deg);
    transform:rotateY(180deg);
}

.notransition {
    display: inline;
    position: fixed;
    width: 100vw;
    height: 100vh;
    top: 0;
    left: 0;
}

// medium resolution / animation works
@media print, screen and (min-width: 40em) {
    .notransition {
       -webkit-transform:unset;
        transform:unset;
    }
}
luiscla27
  • 4,956
  • 37
  • 49