javascript - 使用 javascript 更改光标样式

标签 javascript cursor

我正在开发一个使用自定义光标的浏览器游戏。 我正在 CSS 中为整个页面设置自定义光标 (出于某种原因,如果我将其设置为“正文”,有时它会在某些区域变回默认光标)

html {
  cursor: url("http://www.iwansfactory.com/tycoon/defaultcursor.png"), default;
}

我想使用 javascript 覆盖上述 CSS 的 url 属性

例如,当用户移动 map 时,我想使用此自定义光标:

http://www.iwansfactory.com/tycoon/movecursor.png

如何使用 JavaScript 更改此值? 提前致谢! :)

最佳答案

document.documentElement.style.cursor = 'url("http://www.iwansfactory.com/tycoon/movecursor.png"), default';

关于javascript - 使用 javascript 更改光标样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36442154/

相关文章:

javascript - 试图将游戏光标更改为图像

javascript - 从在 chrome 和 firefox 上运行的 html 页面调用 .dll 函数

ios - 如何在 TWTweetComposeViewController 中设置文本光标的位置?

javascript - 如何使用javascript获取文本光标位置

javascript - Angular JS : How to stop sum of complex filed values crossing a limit?

java - Java 文件中的错误 (Android)

sql - PL/SQL - 你能通过索引访问游标中的特定记录吗?

javascript - 如何更改暂停的 html5 视频的当前时间并从该位置开始播放?

javascript - Google Apps脚本: Find Cells With a Certain Value,然后设置它的背景颜色

javascript - 如何使用javascript访问 Controller 外部的 Angular 范围