想要为更大尺寸的光标使用自定义图像.解决这个问题的方法是什么?有可能用javascript来做吗?

Want to use custom image for cursor of bigger size. What is the workaround for that? Is it possible to do it with javascript?

本文关键字:方法 问题 是什么 javascript 有可能 图像 自定义 光标 解决      更新时间:2023-09-26
$('#dustingBrush').unbind('click').bind('click' , function () {
    $(".section, window.parent.document").css({"cursor": "url("+localImagePath + data.brushPointer1+"),pointer"});
    $(this).css("display" , "none");
});

游标图像来自json,但当我使用更大尺寸的图像时,它并没有反映出来,但是它在较小的图像中工作得很好。

请建议我解决这个问题的方法。

谢谢…

请参阅https://developer.mozilla.org/en-US/docs/Web/CSS/cursor/url的限制部分Firefox允许您使用128×128px图像。较大的图像被忽略。根据本文,您应该将自己的大小限制为32×32,以最大限度地与操作系统和平台兼容

解决方法是隐藏光标并使用包含较大图像的尾随div。

这将模拟更大游标的行为。

示例CSS, html和jquery如下所示。

CSS:

#replacePointer {
    position: absolute;
    cursor:none;
}
HTML:

<div id="replacePointer"><img src="http://www.w3schools.com/images/w3logotest2.png" /></div>
Jquery:

$(document).bind('mousemove', function(e){
$('#replacePointer').css({
    left:  e.pageX -10,
    top:   e.pageY -10
});
});