简体   繁体   English

使用javascript自定义大鼠标光标

[英]Custom large mouse cursor with javascript

I want to create custom cursor image, but it is limited to 32x32, while I need about 300x300 image.我想创建自定义光标图像,但限制为 32x32,而我需要大约 300x300 的图像。 So it seems that I need to hide cursor cursor: none and create custom large div or image, that will be moving with invisible mouse.所以似乎我需要隐藏光标cursor: none并创建自定义的大 div 或图像,这将随着隐形鼠标移动。

The simplest implementation could be:最简单的实现可能是:

$(document).on('mousemove', function(e){
     $('#custom-cursor').css({
          left:  e.pageX,
          top:   e.pageY
     });
});

but I have some problems:但我有一些问题:

  1. Performance (how should I implement moving div not with left-top properties)性能(我应该如何实现不使用左上属性的移动 div)
  2. Text selection jsfiddle cannot select text properly文本选择jsfiddle无法正确选择文本

Can anyone help me with this?谁能帮我这个?

On modern browsers , you need to use pointer-event CSS property set to none :现代浏览器上,您需要使用设置为none pointer-event CSS 属性:

--DEMO-- --演示--

$(document).on('mousemove', function (e) {
    $('#custom-cursor').css({
        left: e.pageX,
        top: e.pageY,
        pointerEvents: 'none'
    });
});

If Cursor and Text are in the same Color, add z-index: -1 to the cursor.如果 Cursor 和 Text 的颜色相同,则将 z-index: -1 添加到光标。 So the cursor is behind the text and lets you select it.所以光标在文本后面,让你选择它。

But if the color is not equal the user will see, that the cursor is behind the text.但是如果颜色不相等,用户会看到,光标在文本后面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM