我对如何做到这一点有点失落。我制作的代码适用于更改我网站上的光标;但是,我希望它只在用户移动鼠标时生效,然后在用户停止移动鼠标时恢复为默认光标。
到目前为止,这是我的代码:
<style type="text/css">body, a:hover {cursor: url(https://www.weebly.com/weebly/images/file_icons/image.png), progress !important;}</style>
答案 0 :(得分:2)
您可以使用一些JavaScript来添加和删除CSS类。
在CSS中添加一个类:
.change-cursor {
cursor: url(https://www.weebly.com/weebly/images/file_icons/image.png), progress !important;
}
然后在你的JavaScript中:
var timeout;
document.onmousemove = function() {
// Clear timeout, as mouse is still moving
clearTimeout(timeout);
// Add class, as mouse is still moving
document.querySelector('body ').classList.add('change-cursor')
// Schedule class to be removed very shortly in the future
timeout = setTimeout(function() {
document.querySelector('body').classList.remove('change-cursor')
}, 100)
}