html,css - cursor - 如何更改指针的默认图像 [英] html, css - cursor - how to change default image for pointer
问题描述
我需要用一些自定义图片更改cursor:指针的默认图片。
I need to change the default image for cursor: pointer with some custom image.
要创建类并指定游标的悬停值不是有效的解决方案因为我必须将这个类添加到所有已经创建的元素,你知道...不完全最优。
To create a class and specify the hover value for cursor is not a valid solution since I would have to add that class to all elements already made and is you know... not exactly optimal. Also can't add that class to body since the children with cursor: pointer would overwrite it.
任何想法如何做?
blockquote>
我误解了,首先,但阅读此评论,事情更清晰。
您可以使用jQuery / JavaScript轻松地完成此操作。首先,这里是稍微简单的jQuery版本:
You can do this easily using jQuery/JavaScript. First, here's the slightly-simpler jQuery version:
$("*").each(function() {
var cur = $(this);
if(cur.css("cursor") == "pointer") {
cur.css("cursor", "url(newcursor.ico)");
}
});
Pure JavaScript版本:
Pure JavaScript version:
var elms = document.getElementsByTagName("*");
var n = elms.length;
for(var i = 0; i < n; i ++) {
if(window.getComputedStyle(elms[i]).cursor == "pointer") {
elms[i].style.cursor = "url(newcursor.ico)";
}
}
这篇关于html,css - cursor - 如何更改指针的默认图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!