JSFiddle - React, Tailwind, and code Playground

by ghayes

HTML

<div class="what">
    <div class="hi">
        <div class="hello">
            Hello
        </div>
    </div>
</div>

CSS

.hello {
  margin: 200px auto;
  width: 100px;  
  background-color:red;
}

@-webkit-keyframes spin @-moz-keyframes spin {
    0% { -webkit-transform: rotate(0deg); 0% { -moz-transform: rotate(0deg); }
    40% { -webkit-transform: rotate(-45deg); 40% { -moz-transform: rotate(-45deg); }
    70% { -webkit-transform: rotate(15deg);  70% { -moz-transform: rotate(15deg); }
    85% { -webkit-transform: rotate(-5deg); -moz-transform: rotate(-5deg); }
    100% { -webkit-transform: rotate(0deg); 100% { -moz-transform: rotate(0deg); }    
}

@-o-keyframes spin {
    0% { -o-transform: rotate(0deg); }
    40% { -o-transform: rotate(-45deg); }
    70% { -o-transform: rotate(15deg); }
    85% { -o-transform: rotate(-5deg); }
    100% { -o-transform: rotate(0deg); }    
}

@-ms-keyframes spin {
    0% { -ms-transform: rotate(0deg); }
    40% { -ms-transform: rotate(-45deg); }
    70% { -ms-transform: rotate(15deg); }
    85% { -ms-transform: rotate(-5deg); }
    100% { -ms-transform: rotate(0deg); }    
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    40% { transform: rotate(-45deg); }
    70% { transform: rotate(15deg); }
    85% { transform: rotate(-5deg); }
    100% { transform: rotate(0deg); }    
}

.hello.spin {
    -webkit-animation-name: spin;
    -webkit-animation-duration: 2s;
    -webkit-animation-iteration-count: 1;
    -webkit-animation-timing-function: ease-in-out;

    -moz-animation-name: spin;
    -moz-animation-duration: 2s;
    -moz-animation-iteration-count: 1;
    -moz-animation-timing-function: ease-in-out;
    
    -o-animation-name: spin;
    -o-animation-duration: 2s;
    -o-animation-iteration-count: 1;
    -o-animation-timing-function: ease-in-out;
    
    -ms-animation-name: spin;
    -ms-animation-duration: 2s;
    -ms-animation-iteration-count: 1;
    -ms-animation-timing-function: ease-in-out;
    
    animation-name: spin;
    animation-duration: 2s;
    animation-iteration-count: 1;
    animation-timing-function: ease-in-out;
}

JavaScript

$('.hello').click(function() {
  var that = $(this);
  if (that.css('-webkit-transform') == 'none' ||
      that.css('-moz-transform') == 'none' ||
      that.css('-o-transform') == 'none' ||
      that.css('-ms-transform') == 'none' ||
      that.css('transform') == 'none') {
    that.removeClass('spin').width();
    that.addClass('spin');
  }
});