my purpose is that to animate the DIV Box everytime when browser Tab is active (means i switch the tab to other & back to this tab), As i am adding addEventListener & its working but one time only, not everytime. 
But when i open Developer tools in chrome it's work everytime. 
Check this video to better understand my problem: https://youtu.be/9Uvm__ln6zE
JS Class remove not working properly, Dev Tools problem
document.addEventListener("visibilitychange", () => {
    if(document.visibilityState === "visible" ){
  var element = document.getElementById("topHeading");
  element.classList.add("r1");
}
else{
 var element = document.getElementById("topHeading");
  element.classList.remove("r1");
}
});.r1 {
  background-color: lightgrey;
  width: 300px;
  height: 50px;
  border: 6px solid green;
  padding: 10px;
  text-align: center;
visibility: visible;
}
.r2 {
  background-color: red;
  
}
.r1 {
    animation: bounceInRight 1400ms both
}
@keyframes bounceInRight {
    from,
    60%,
    75%,
    90%,
    to {
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }
    from {
        opacity: 0;
        transform: translate3d(3000px, 0, 0);
    }
    60% {
        opacity: 1;
        transform: translate3d(-25px, 0, 0);
    }
    75% {
        transform: translate3d(10px, 0, 0);
    }
    90% {
        transform: translate3d(-5px, 0, 0);
    }
    to {
        transform: translate3d(0, 0, 0);
    }
}<div id="topHeading">
This text is the content of the box..
</div>Thanks in advance
 
     
    