Safari Animations

by dhwanilshah

HTML

<div>

  <button onclick="animator()">
Animate
</button>
  <table>
    <tr id="row-1" class="transparent_element animate-row-1" style="-webkit-box-shadow: 6px 4px 11px 1px rgba(0,0,0,0.75); -moz-box-shadow: 6px 4px 11px 1px rgba(0,0,0,0.75); box-shadow: 6px 4px 11px 1px rgba(0,0,0,0.75);  height: 90px;">
    </tr>
    <tr id="row-2" class="transparent_element animate-row-2" style="-webkit-box-shadow: 6px 4px 11px 1px rgba(0,0,0,0.75); -moz-box-shadow: 6px 4px 11px 1px rgba(0,0,0,0.75); box-shadow: 6px 4px 11px 1px rgba(0,0,0,0.75);  height: 90px;">
    </tr>
  </table>

  <div id="table" class="transparent_element animate-table"></div>
  <div id="chart" class="transparent_element animate-chart"></div>

</div>
</div>

CSS

.transparent_element {
  opacity: 0;
}

#row-1 {
  width: 300px;
  height: 100px;
  display: block;
  background-color: green;
}

#row-2 {
  width: 300px;
  height: 100px;
  display: block;
  background-color: yellow;
}

#table {
  width: 150px;
  height: 150px;
  background-color: red;
  display: inline-block;
}

#chart {
  width: 150px;
  height: 150px;
  background-color: blue;
  position: absolute;
  right: 0;
  display: inline-block;
}

@-webkit-keyframes slideLeftAppear {
  0% {
    opacity: 0;
    transform: translate3d(100%, 0, 0);
    -webkit-transform: translate3d(100%, 0, 0);
  }
  100% {
    transform: translate3d(0, 0, );
    -webkit-transform: translate3d(0);
    position: relative;
    display: block;
    opacity: 1;
  }
}

@keyframes slideLeftAppear {
  0% {
    opacity: 0;
    transform: translateX(100%);
    -webkit-transform: translateX(100%);
  }
  100% {
    transform: translateX(0);
    -webkit-transform: translateX(0);
    position: relative;
    display: block;
    opacity: 1;
  }
}

@-webkit-keyframes slideRightDisappear {
  0% {
    opacity: 1;
  }
  75% {
    opacity: 0;
  }
  99% {
    transform: translateX(100%);
    -webkit-transform: translateX(100%);
  }
  100% {
    position: absolute;
  }
}

@keyframes slideRightDisappear {
  0% {
    opacity: 1;
  }
  75% {
    opacity: 0;
  }
  99% {
    transform: translateX(100%);
    -webkit-transform: translateX(100%);
  }
  100% {
    position: absolute;
  }
}

@-webkit-keyframes fadeInLeftBig {
  0% {
    opacity: 0;
    -webkit-transform: translateX(-400px);
    transform: translateX(-400px);
  }
  100% {
    opacity: 1;
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }
}

@keyframes fadeInLeftBig {
  0% {
    opacity: 0;
    -webkit-transform: translateX(-400px);
    transform: translateX(-400px);
  }
  100% {
    opacity: 1;
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }
}

@-webkit-keyframes fadeInRightBig {
  0% {
    opacity: 0;
   ...

JavaScript

function animator() {
  addAnimationToElement('row-1', ['fadeInLeftBig', 'slideRightDisappear', 'slideLeftAppear'], ['0.5s', '0.3s', '0.5s'], ['linear', 'linear', 'linear'], ['0.6s', '3s', '7.5s'], ['1', '1', '1'], ['normal', 'normal', 'normal'], ['forwards', 'forwards', 'forwards'], ['running', 'running', 'running'])

  addAnimationToElement('row-2', ['slideInLeft', 'slideLeftDisappear'], ['0.5s', '0.5s'], ['linear', 'linear'], ['4s', '6.5s'], ['1', '1'], ['normal', 'normal'], ['forwards', 'forwards'], ['running', 'running'])

  addAnimationToElement('table', ['fadeInLeftBig'], ['1.5s'], ['linear'], ['9s'], ['1'], ['normal'], ['forwards'], ['running'])

  addAnimationToElement('chart', ['fadeInRightBig'], ['1.5s'], ['linear'], ['9s'], ['1'], ['normal'], ['forwards'], ['running'])

}

function addAnimationToElement(elementID, animationName, animationDuration, animationTimingFunction, animationDelay, animationIterationCount, animationDirection, animationFillMode, animationPlayState) {
  // Animation for Safari
  document.getElementById(elementID).style.WebkitAnimationName = animationName.join(', ')
  document.getElementById(elementID).style.WebkitAnimationDuration = animationDuration.join(', ')
  document.getElementById(elementID).style.WebkitAnimationTimingFunction = animationTimingFunction.join(', ')
  document.getElementById(elementID).style.WebkitAnimationDelay = animationDelay.join(', ')
  document.getElementById(elementID).style.WebkitAnimationIterationCount = animationIterationCount.join(', ')
  document.getElementById(elementID).style.WebkitAnimationDirection = animationDirection.join(', ')
  document.getElementById(elementID).style.WebkitAnimationFillMode = animationFillMode.join(', ')
  document.getElementById(elementID).style.WebkitAnimationPlayState = animationPlayState.join(', ')
  // Animation for other browsers
  document.getElementById(elementID).style.animationName = animationName.join(', ')
 ...