Java 移动时更改鼠标光标

Java 移动时更改鼠标光标,java,jquery,html,css,cursor,Java,Jquery,Html,Css,Cursor,我不知道该怎么做。我制作的代码可以很好地更改我网站上的光标;但是,我希望它仅在用户移动鼠标时生效,然后在用户停止移动鼠标时恢复为默认光标 以下是我目前的代码: <style type="text/css">body, a:hover {cursor: url(https://www.weebly.com/weebly/images/file_icons/image.png), progress !important;}</style> body,a:hover{curs

我不知道该怎么做。我制作的代码可以很好地更改我网站上的光标;但是,我希望它仅在用户移动鼠标时生效,然后在用户停止移动鼠标时恢复为默认光标

以下是我目前的代码:

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

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

}

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

}