Check out this code: https://codepen.io/sabeser/pen/BaOeBPW
:root {
--scale--ratio: 1;
}
#wrapper {
background-color: yellow;
display: flex;
justify-content: center;
align-items: center;
height: 50vh;
width: 50vw;
}
.circle {
background-color: red;
width: 50px;
height: 50px;
border-radius: 20em;
-webkit-animation: floataround 1.1s infinite alternate;
animation: floataround 1.1s infinite alternate;
transform: scale(var(--scale--ratio)) translate(0%, 0%);
transform-origin: 0% 0%;
transition: transform .9s;
margin: 1em;
}
@keyframes floataround {
0% {
transform: translateY(0);
}
100% {
transform: translateY(-8px);
}
}
.circle:hover {
cursor: pointer;
background-color: green;
--scale--ratio: 1.2;
}
<div id='wrapper'>
<div class='circle'>
</div>
<div class='circle'>
</div>
</div>
You'll notice two circles moving up and down in the demo:
https://i.sstatic.net/xeKIa.png
However, when trying to make each circle scale on hover, problems arise due to conflicting code:
-webkit-animation: floataround 1.1s infinite alternate;
animation: floataround 1.1s infinite alternate;
How can I achieve both animations without interference?