2013-02-22 47 views
0

我想为我的基于浏览器的游戏隐藏光标。在比赛开始之前我不想这样做。如何将此CSS转换为javascript

我在CSS:* { cursor: none }。我将如何在JavaScript中做到这一点?我的目标浏览器是Chrome,只有Chrome。

+0

请参阅:http://stackoverflow.com/questions/1071356/is-it-possible-to-hide-the-cursor-in-a-webpage-using-css-or-javascript#1071363 – looper 2013-02-22 12:26:19

回答

2

你可以做

document.body.style.cursor='none'; 

的注意事项你的CSS:这是更好地避免尽可能的*选择,尤其是当你可以只设置一个样式的身体。

+2

请不要这等于'body {cursor:none}'。如果你想在JavaScript中使用'*'选择器,请参见[这个问题](http://stackoverflow.com/a/4256372/1149495) – 2013-02-22 12:29:42

+1

@WouterJ这里很好的解决方案是避免使用'*'。 – 2013-02-22 12:31:25

+2

是的,我知道。这就是为什么我将它添加为评论而不是答案。 – 2013-02-22 12:33:43

1
<div id="nocursor"></div> 

<script type="text/javascript"> 
    document.getElementById('nocursor').style.cursor = 'none'; 
</script> 

它仍然使用CSS,但我认为这是你在找的地方。