如何在Chrome中实现抓取光标图标?

Ale*_*lex 46 html javascript css google-chrome

我知道可以在Chrome中使用抓取光标图标(当然是在Gmail中),但我无法弄清楚如何在我的代码中实现它.我试过(在CSS中):

body {
  cursor: grab;
}

body {
  cursor: -webkit-grab;
}


body {
  cursor: url(http://www.worldtimzone.com/mozilla/testcase/css3cursors_files/grab.gif);
}
Run Code Online (Sandbox Code Playgroud)

Ula*_*ach 77

Chrome在"抓取"名称之前需要-webkit-;

下面是一个适用于Chrome和Mozilla的样式示例,其中包括当您"抓住"某些内容时光标的更改.

#eA { cursor: -webkit-grab; cursor:-moz-grab; }
#eA:active { cursor: -webkit-grabbing; cursor:-moz-grabbing;}
Run Code Online (Sandbox Code Playgroud)

参考:https://developer.mozilla.org/en-US/docs/Web/CSS/cursor

  • 我知道这是旧的,但这绝对应该是公认的答案.当浏览器提供自己的游标时使用图像是没有意义的,并且在所有平台上强制使用相同的图标,所以这绝对是不好的做法. (8认同)
  • 使用Firefox 27+,不再需要`-moz -`前缀. (3认同)

Nic*_*ver 14

这是gmail使用的样式,如果这是你想要的精确光标样式:

body {
  cursor: url(https://ssl.gstatic.com/ui/v1/icons/mail/images/2/openhand.cur), default !important;
}
Run Code Online (Sandbox Code Playgroud)

你可以在这里测试一下.

  • 该URL上不再存在该图标 (21认同)
  • 请向下滚动到下面的[answer](http://stackoverflow.com/a/25321042/1159167),因为已接受的一个不再有效. (3认同)

Nic*_*gen 14

因此,在CSS中,您可以从基础开始,然后转向更加模糊的内容.浏览器将选择适用于该特定浏览器的最后一个.无论出于何种原因,Chrome支持webkit-grab但不支持抓取.

body {
  cursor: pointer;
  cursor: hand;
  cursor: -webkit-grab;
  cursor: grab;
}
Run Code Online (Sandbox Code Playgroud)

关于您关于操作此操作的能力的后续问题,请尝试使用以下内容:

document.body.style.cursor = 'move';
Run Code Online (Sandbox Code Playgroud)

  • ...除了浏览器前缀值,因为如果浏览器中的两个值都可以接受,那么您希望它选择一个标准,如果不是,它将忽略前缀的标准.所以你的答案应该交换`grab`和`-webkit-grab`的顺序 (3认同)
  • 请注意,上述评论是在编辑中实现的. (2认同)