我希望当鼠标悬停在图片上时,能够使用双箭头字符作为光标。我只能添加一张图片作为自定义光标吗?
cursor: url(images/my-cursor.png), auto;
我希望当鼠标悬停在图片上时,能够使用双箭头字符作为光标。我只能添加一张图片作为自定义光标吗?
cursor: url(images/my-cursor.png), auto;
这里有一个使用行内SVG的解决方案:
您可以根据需要为文本(字符)调整高度和宽度。您可能还想更改文本的y轴以适应不同的字符。
html {height:100%;}
body {width:100%;height:100%;margin: 0;
/* only this is relevant */
cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="30" style="font-size: 20px;"><text y="15">¶</text></svg>'), auto;
}
虽然这是纯CSS,但你也可以使用HTML5-Canvas并用JavaScript在上面绘制文本:
var canvas = document.createElement("canvas")
canvas.width = 10
canvas.height = 15
var context = canvas.getContext("2d")
context.font = "20px 'sans serif'"
context.fillText("¶", 0, 13)
document.body.style.cursor = "url('" + canvas.toDataURL() + "'), auto"
html {height:100%;}
body {width:100%;height:100%;margin:0;}
canvas
作为url()
属性来设置光标的例子吗? - Ruan Mendesauto
,所以它没起作用 :p - Ruan Mendesvar repl_cursor='url(\'data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="30" style="font-size: 20px;"><text y="15">REPL</text></svg>\'), auto';
document.body.style.cursor=repl_cursor.replace('REPL','¶');
- Chinoto Vokro