JSFiddle - React, Tailwind, and code Playground

HTML

<div id="test"></div>

CSS

#test
{
  width: 200px;
  height: 200px;
}

#test:before
{
  content: url(http://placehold.it/200x200);
  position: relative;
  top: -100%;
  left: 0px;
}

#test.test:before {
   top: 0%;
}

JavaScript

var test = document.getElementById("test");
var span = document.getElementById("change");

setInterval(function(){
  test.className = test.className.indexOf("test") >= 0
    ? test.className.replace("test", "").replace("  ", " ").trim()
    : (test.className + " test").trim();
},3000);