【发布时间】:2011-08-07 12:17:30
【问题描述】:
我有一个 JavaScript webapp,用户需要在其中抓取背景来移动整个屏幕。所以我希望光标在悬停在背景上时发生变化。 -moz-grab 和 -moz-grabbing CSS 游标非常适合这种情况。当然,它们只在 Firefox 中工作......是否有其他浏览器的等效光标?我必须做一些比标准 CSS 光标更自定义的事情吗?
【问题讨论】:
标签: css mouse-cursor
我有一个 JavaScript webapp,用户需要在其中抓取背景来移动整个屏幕。所以我希望光标在悬停在背景上时发生变化。 -moz-grab 和 -moz-grabbing CSS 游标非常适合这种情况。当然,它们只在 Firefox 中工作......是否有其他浏览器的等效光标?我必须做一些比标准 CSS 光标更自定义的事情吗?
【问题讨论】:
标签: css mouse-cursor
如果其他人偶然发现这个问题,这可能就是您要寻找的:
.grabbable {
cursor: move; /* fallback if grab cursor is unsupported */
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
}
/* (Optional) Apply a "closed-hand" cursor during drag operation. */
.grabbable:active {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}
【讨论】:
grabbable 类添加到任何可以抓取的元素中,并且当它们被拖动时您正在切换类。
grab 光标设置在 :hover 而不是普通选择器上,即上面示例中的 .grabbable:hover。
<ul> 而不是 <li> 在我的情况下解决了问题
我认为move 可能是最接近你正在做的事情的standard cursor value:
移动
表示要移动的东西。
【讨论】:
cursor:move; cursor:-webkit-grab; cursor:-moz-grab; cursor:grab;,最喜欢最后一个。
cursor: url(example.svg#linkcursor), url(hyper.cur), pointer 而不是多个可能的值,则逗号列表有效。我认为你的方法可能是必要的。
CSS3 grab 和 grabbing 现在是 cursor 的允许值。
为了为 cross-browser compatibility3 提供多个备用方案,包括自定义光标文件,完整的解决方案如下所示:
.draggable {
cursor: move; /* fallback: no `url()` support or images disabled */
cursor: url(images/grab.cur); /* fallback: Internet Explorer */
cursor: -webkit-grab; /* Chrome 1-21, Safari 4+ */
cursor: -moz-grab; /* Firefox 1.5-26 */
cursor: grab; /* W3C standards syntax, should come least */
}
.draggable:active {
cursor: url(images/grabbing.cur);
cursor: -webkit-grabbing;
cursor: -moz-grabbing;
cursor: grabbing;
}
2019 年 10 月 7 日更新:
.draggable {
cursor: move; /* fallback: no `url()` support or images disabled */
cursor: url(images/grab.cur); /* fallback: Chrome 1-21, Firefox 1.5-26, Safari 4+, IE, Edge 12-14, Android 2.1-4.4.4 */
cursor: grab; /* W3C standards syntax, all modern browser */
}
.draggable:active {
cursor: url(images/grabbing.cur);
cursor: grabbing;
}
【讨论】:
grab的浏览器提供了一个光标图像,但提供了光标图像。其次,最好在供应商前缀值之后使用标准语法。
images/grab.cur 一个我需要在我的网络服务器上托管的图像的示例 URL,或者是一些神奇的 IE 东西?
比 CSS 游标“更自定义”意味着某种类型的插件,但您完全可以使用 CSS 指定自己的游标。我认为这个列表有你想要的:
.alias {cursor: alias;}
.all-scroll {cursor: all-scroll;}
.auto {cursor: auto;}
.cell {cursor: cell;}
.context-menu {cursor: context-menu;}
.col-resize {cursor: col-resize;}
.copy {cursor: copy;}
.crosshair {cursor: crosshair;}
.default {cursor: default;}
.e-resize {cursor: e-resize;}
.ew-resize {cursor: ew-resize;}
.grab {cursor: grab;}
.grabbing {cursor: grabbing;}
.help {cursor: help;}
.move {cursor: move;}
.n-resize {cursor: n-resize;}
.ne-resize {cursor: ne-resize;}
.nesw-resize {cursor: nesw-resize;}
.ns-resize {cursor: ns-resize;}
.nw-resize {cursor: nw-resize;}
.nwse-resize {cursor: nwse-resize;}
.no-drop {cursor: no-drop;}
.none {cursor: none;}
.not-allowed {cursor: not-allowed;}
.pointer {cursor: pointer;}
.progress {cursor: progress;}
.row-resize {cursor: row-resize;}
.s-resize {cursor: s-resize;}
.se-resize {cursor: se-resize;}
.sw-resize {cursor: sw-resize;}
.text {cursor: text;}
.url {cursor: url(https://www.w3schools.com/cssref/myBall.cur),auto;}
.w-resize {cursor: w-resize;}
.wait {cursor: wait;}
.zoom-in {cursor: zoom-in;}
.zoom-out {cursor: zoom-out;}
<h1>The cursor Property</h1>
<p>Hover mouse over each to see how the cursor looks</p>
<p class="alias">cursor: alias</p>
<p class="all-scroll">cursor: all-scroll</p>
<p class="auto">cursor: auto</p>
<p class="cell">cursor: cell</p>
<p class="context-menu">cursor: context-menu</p>
<p class="col-resize">cursor: col-resize</p>
<p class="copy">cursor: copy</p>
<p class="crosshair">cursor: crosshair</p>
<p class="default">cursor: default</p>
<p class="e-resize">cursor: e-resize</p>
<p class="ew-resize">cursor: ew-resize</p>
<p class="grab">cursor: grab</p>
<p class="grabbing">cursor: grabbing</p>
<p class="help">cursor: help</p>
<p class="move">cursor: move</p>
<p class="n-resize">cursor: n-resize</p>
<p class="ne-resize">cursor: ne-resize</p>
<p class="nesw-resize">cursor: nesw-resize</p>
<p class="ns-resize">cursor: ns-resize</p>
<p class="nw-resize">cursor: nw-resize</p>
<p class="nwse-resize">cursor: nwse-resize</p>
<p class="no-drop">cursor: no-drop</p>
<p class="none">cursor: none</p>
<p class="not-allowed">cursor: not-allowed</p>
<p class="pointer">cursor: pointer</p>
<p class="progress">cursor: progress</p>
<p class="row-resize">cursor: row-resize</p>
<p class="s-resize">cursor: s-resize</p>
<p class="se-resize">cursor: se-resize</p>
<p class="sw-resize">cursor: sw-resize</p>
<p class="text">cursor: text</p>
<p class="url">cursor: url</p>
<p class="w-resize">cursor: w-resize</p>
<p class="wait">cursor: wait</p>
<p class="zoom-in">cursor: zoom-in</p>
<p class="zoom-out">cursor: zoom-out</p>
【讨论】:
您可以创建自己的光标并使用 cursor: url('path-to-your-cursor'); 将它们设置为光标,或者找到 Firefox 并复制它们(奖励:在每个浏览器中都有一个很好的一致外观)。
【讨论】:
闭合的手形光标不是 16x16。如果您需要它们的尺寸相同,那么您可以将它们都设置为 16x16 像素
或者如果您需要原始光标:
https://www.google.com/intl/en_ALL/mapfiles/openhand.cur https://www.google.com/intl/en_ALL/mapfiles/closedhand.cur
【讨论】: