The idea is I want the color of a text to change after I hover over. The text color will be the current color of my "cursor" at the moment I hovered over the text.
Cursor Example:
#cursor{
position: absolute;
top: 4.6%;
left: 6.5%;
width: 30px;
height: 30px;
background: #000000 ;
border:none;
box-sizing: border-box;
transform: translate(-50%, -50%);
border-radius: 50%;
pointer-events: none;
transition: 0.2s;
z-index: -1;
}
#cursor {
animation: color-change 10s infinite;
}
@keyframes color-change {
0% { background: rgb(0, 0, 0); }
10% { background: red; }
20% { background: rgb(255, 81, 0); }
30% { background: rgb(255, 238, 0); }
40% { background: rgb(136, 255, 0); }
50% { background: rgb(0, 255, 21); }
60% { background: rgb(0, 255, 179); }
70% { background: rgb(0, 119, 255); }
80% { background: rgb(76, 0, 255); }
90% { background: rgb(255, 0, 170); }
100% { background: rgb(255, 0, 85); }
}
<div id="cursor"></div>
<script type="text/javascript">
var cursor = document.getElementById('cursor');
document.addEventListener('mousemove' , function(e) {
var x = e.clientX;
var y = e.clientY;
cursor.style.left = x + "px";
cursor.style.top = y + "px";
});
</script>
How can I get the color of a @keyframes CSS animation?