I am trying to perform a animation of background image changing the div class. The animation seems that works at first, when I change the class the animation is done perfectly. However when I change the class again while the animation is running, it stops inmediately and last class is set (without animation).
I did the same with colors instead of images and when I changed the div class while animation was running, the new animation was "interpolated" with the previous one.
There is some way to solve this??
Here is a snippet where you can reproduce it:
.base-class {
transition: background linear 1s;
}
.base-class.green {
background: url("https://upload.wikimedia.org/wikipedia/commons/thumb/4/4b/Flag_of_Libya_(1977-2011).svg/1280px-Flag_of_Libya_(1977-2011).svg.png");
}
.base-class.lightblue {
background: url("https://upload.wikimedia.org/wikipedia/commons/thumb/f/f5/F1_light_blue_flag.svg/2000px-F1_light_blue_flag.svg.png");
}
.base-class.yellow {
background: url("https://lh3.googleusercontent.com/nhzkOTPaoWAYfO-LeklB_kPd5bAqm43D87Q3eHlK3alIse8rgrYPE74epbbbZ2b4EsY=w300");
}
.base-class.green2 {
background: green;
}
.base-class.lightblue2 {
background: lightblue;
}
.base-class.yellow2 {
background: yellow;
}
.base-class.my-class {
color: red;
font-size: 3em;
}
<html>
<head>
</head>
<body>
<h1>With Images</h1>
<div>
<input type="button" value="clear" onclick="document.getElementById('target1').className = 'base-class';">
<input type="button" value="my-class" onclick="document.getElementById('target1').className = 'base-class my-class';">
<input type="button" value="green" onclick="document.getElementById('target1').className = 'base-class green';">
<input type="button" value="lightblue" onclick="document.getElementById('target1').className = 'base-class lightblue';">
<input type="button" value="yellow" onclick="document.getElementById('target1').className = 'base-class yellow';">
<br>
<div id="target1" class="base-class">
<br><br><br><br><br> Sample Text
<br><br><br><br><br>
</div>
</div>
<h1>With Colors</h1>
<div>
<input type="button" value="clear" onclick="document.getElementById('target2').className = 'base-class';">
<input type="button" value="my-class" onclick="document.getElementById('target2').className = 'base-class my-class';">
<input type="button" value="green" onclick="document.getElementById('target2').className = 'base-class green2';">
<input type="button" value="lightblue" onclick="document.getElementById('target2').className = 'base-class lightblue2';">
<input type="button" value="yellow" onclick="document.getElementById('target2').className = 'base-class yellow2';">
<br>
<div id="target2" class="base-class">
<br><br><br><br><br> Sample Text
<br><br><br><br><br>
</div>
</div>
</body>
</html>