I have a single <div>
on my page. red square and I want 2 animations to be applied to it:
- Move this square on page load
- Change the colour of the square on mouse hover
Here is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.animation {
width: 150px;
height: 150px;
background-color: red;
animation-name: anim;
animation-duration: 3s;
animation-fill-mode: forwards;
}
.animation:hover {
animation-name: hover;
animation-duration: 1s;
}
@keyframes anim {
from {
}
30% {
transform: translateX(100px);
}
70% {
transform: translate(100px, 100%);
/*background-color: blue;*/
}
100% {
transform: translate(100px, 100%) scale(2, 2) rotate(145deg);
}
}
@keyframes hover {
from {
}
to {
background:yellow;
}
}
</style>
</head>
<body>
<div class="animation">
</div>
</body>
</html>
https://jsfiddle.net/tbqj4goy/
The problem with it is that when I hover the mouth the first annimation interrupts and starts from the beginning.
Any ideas how to let these annimation collaborate without problems?