【发布时间】:2021-09-09 00:54:49
【问题描述】:
我的想法是我希望在鼠标悬停后改变文本的颜色。当我将鼠标悬停在文本上时,文本颜色将是我的“光标”的当前颜色。
光标示例:
#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>
如何获得@keyframes CSS 动画的颜色?
【问题讨论】:
标签: javascript html css dom css-animations