gpt4 book ai didi

java - 移动时更改鼠标光标

转载 作者:太空宇宙 更新时间:2023-11-04 01:34:38 25 4
gpt4 key购买 nike

我对如何执行此操作有点不知所措。我编写的代码可以很好地更改我网站上的光标;但是,我希望它仅在用户移动鼠标时生效,然后在用户停止移动鼠标时恢复为默认光标。

到目前为止,这是我的代码:

<style type="text/css">body, a:hover {cursor: url(https://www.weebly.com/weebly/images/file_icons/image.png), progress !important;}</style>

最佳答案

您可以使用一些 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)

}

关于java - 移动时更改鼠标光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474644/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com