Animation How to - Create CSS animation that prevents subsequently styling the animated properties








Question

We would like to know how to create CSS animation that prevents subsequently styling the animated properties.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
@-webkit-keyframes slideInFromBottom {<!--from   w  w w  .  j a  va2 s  .  c o  m-->
   from { opacity:0;transform: translate3d(0, 400px, 0);}
}
.parent {
  background-color: green;
  height: 400px;
  width: 400px;
}

.child {
  background-color: red;
  width: 200px;
  height: 200px;
  -webkit-animation: slideInFromBottom 1s cubic-bezier(0.7, 0, 0.3, 1) both;
  -webkit-animation-delay: 1s;
}

.newstate .child {
  background-color: rgba(0, 0, 255, 0.5);
}
</style>
<script type='text/javascript'>
window.onload=function(){
    setTimeout(function(){
        document.body.classList.add('newstate');
    }, 3 * 1000)
}
</script>
</head>
<body>
  <div class="parent">
    <div class="child">hello</div>
  </div>
</body>
</html>

The code above is rendered as follows: