<div class="wrap--main">
  <h1 class="intro__header">Perfomant CSS animation for beginners</h1>
  
  <div class="grid-r">
    <div class="grid-u-sm-1 grid-u-md-1-2">
      <div class="box"><img src="https://fillmurray.com/200/200" alt=""></div>
      <div class="btn__wrap">
        <button id="js-opacity" class="btn">Opacity</button>
        <button id="js-translate" class="btn btn-two">Translate</button>
        <button id="js-scale" class="btn btn-three">Scale</button>
        <button id="js-rotate" class="btn btn-four">Rotate</button>
      </div>
    </div>
    
    <div class="intro__wrap grid-u-sm-1 grid-u-md-1-2">
      <p class="intro__p">As a general rule, there are only four properties which you can animate whilst maintaining a silky smooth experience for your users. They are: Opacity, Translate, Scale & Rotation. You'll be surprised what you can achieve with only these parameters. Animating 'fixed' elements can result in a screen 're-paint' and a 'janky' transition.<br /> Here, I've chosen to use jQuery to toggle classes because it's eaiser for begininers to read, but I would recommend handling such simple animations with 'vanilla' Javascript. <br />
      <a href="https://twitter.com/IHazelton" class="follow">@IHazelton</a></p>

  <div class="code__wrap">
    <code><pre>

/* the box in its original state*/
.box {
  transition: all 300ms;
}

/* with opacity class */
.box.removeOpacity {
  opacity: 0;
}

/* with translate class */
.box.moveX {
  transform: translateX(100px);
}

/* with scale class */
.box.scale {
   transform: scale(0.4);
}

/* with rotate class */
.box.rotate {
  transform: rotate(45deg);
}

</pre></code>
  </div>
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:300,400,700');

$bodyBg: #fff;
$codeBg: #cacaca;
$textPrimary: #333;
$btnActive: rgba(0,0,0,0.5);
$btnTwo: #2ecc71;
$btnThree: #e74c3c;
$btnFour: #2980b9;

body {
  background-color: $bodyBg;
}
  
.wrap--main {
  padding: 0 5rem;  
}

.intro__header {
  color: $textPrimary;
  font-family: 'Roboto Mono', monospace;
  font-size: 2.4rem;
  line-height: 1.3;
  margin: 1.8rem;
  padding: 3rem;
  text-align: center;
}

.intro__p {
  color: $textPrimary;
  font-size: 1.6rem;
  font-family: 'Roboto Mono', monospace;
  padding: 0 2rem;
    @include breakpoint(md) {
    margin-top: 2rem;
  }
}
 
.follow {
  font-weight: bold;
  &:hover {
    text-decoration: underline;
  }
}

.box {
  background-color: $textPrimary;
  height: 20rem;
  margin: 5rem auto;
  transition: all 300ms;
  width: 20rem;
  &.--opac {
    opacity: 0;
  }
  &.--move {
    transform: translateX(50vw);    
  }
  &.--scaled {
    transform: scale(0.4);
  }
  &.--turn {
    transform: rotate(45deg);
  }
}  
    
.btn__wrap {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
  
.btn {
  color: $bodyBg;
  background-color: #9b59b6;
  cursor: pointer;
  font-family: 'Roboto Mono', monospace;
  font-weight: bold;
  margin: .75rem 0;
  padding: 1.5rem 0;
  width: 20rem;
  &.--active {
    background-color: $btnActive;
  } 
  &-two {
    background-color: $btnTwo;
  } 
  &-three {
    background-color: $btnThree;
  } 
  &-four {
    background-color: $btnFour;
  }
} 
    
.code__wrap {
  background-color: $codeBg;
  color: $textPrimary;
  font-size: 1.3rem;
  margin: 0 auto;
  padding-left: 2rem;
}
  
View Compiled
$('.btn').click(function(e){
    $(this).toggleClass('--active');
});

$('#js-opacity').click(function(e){
  e.preventDefault();
  $('.box').toggleClass('--opac');
});

$('#js-translate').click(function(e){
  e.preventDefault();
  $('.box').toggleClass('--move');
});

$('#js-scale').click(function(e){
  e.preventDefault();
  $('.box').toggleClass('--scaled');
});

$('#js-rotate').click(function(e){
  e.preventDefault();
  $('.box').toggleClass('--turn');
});
Run Pen

External CSS

  1. https://codepen.io/IanHazelton/pen/RWXGep

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js