使用 JavaScript 更改鼠标指针
我想使用 JavaScript 脚本来更改网站上的鼠标指针。 最好用 CSS 来完成,但我的要求是一个可以分发给很多人以嵌入到他们网站的头部部分的脚本。 通过CSS,可以通过
html
{
cursor: *cursorurl*
}
How to do the same in JavaScript?来操作它。
I wanted to use a script to change the mouse pointer on my website using JavaScript.
It's better done by CSS but my requirement is of a script that can be distributed to many people to embed in the head section of their websites.
Through CSS, this can be manipulated by
html
{
cursor: *cursorurl*
}
How to do the same in JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Body 可能有余量,所以更好的解决方案是:
Body may have margin, so better solution will be:
JavaScript 非常擅长操作 CSS:
或使用 jQuery:
Firefox 将无法工作,除非您在图像后指定默认光标!
其他光标关键字
另请记住,IE6 仅支持 .cur 和 .ani 光标。
如果光标没有改变:如果您相对于光标位置移动光标下的元素(例如元素拖动),则必须强制重绘元素:
工作示例:
JavaScript is pretty good at manipulating CSS:
or with jQuery:
Firefox will not work unless you specify a default cursor after the imaged one!
other cursor keywords
Also remember that IE6 only supports .cur and .ani cursors.
If cursor doesn't change: In case you are moving the element under the cursor relative to the cursor position (e.g. element dragging) you have to force a redraw on the element:
working sample:
查看此页面:http://www.webcodingtech.com/javascript/change-cursor。 php.看起来您可以脱离样式访问光标。此页面显示整个页面都已完成此操作,但我确信子元素也可以正常工作。
Look at this page: http://www.webcodingtech.com/javascript/change-cursor.php. Looks like you can access cursor off of style. This page shows it being done with the entire page, but I'm sure a child element would work just as well.