Javascript 是否可以更改光标的形状和大小?

Javascript 是否可以更改光标的形状和大小?,javascript,html,css,Javascript,Html,Css,有没有可能通过像这张图片一样的两条线来改变光标的形状和大小 是的,可以通过javascript和CSS3更改光标的形状和大小。看看这些资源,他们有一些很好的信息让你开始 下面是另一个SO用户()的代码片段 测试 #保持{边距:0自动;宽度:500px;高度:500px;边框:1px实心#000;} #画布{float:left;} #顶层{位置:绝对;z索引:1;宽度:500px;高度:500px;光标:十字线;} var ctx=document.getEleme

有没有可能通过像这张图片一样的两条线来改变光标的形状和大小


是的,可以通过javascript和CSS3更改光标的形状和大小。看看这些资源,他们有一些很好的信息让你开始




下面是另一个SO用户()的代码片段


测试
#保持{边距:0自动;宽度:500px;高度:500px;边框:1px实心#000;}
#画布{float:left;}
#顶层{位置:绝对;z索引:1;宽度:500px;高度:500px;光标:十字线;}
var ctx=document.getElementById('canvas').getContext('2d'); 功能跟踪鼠标(事件){ ctx.globalCompositeOperation=“源代码结束”; ctx.clearRect(0,0500500); this.r=25;//圆的半径 这个.x; 这个.y; this.x=event.clientX-document.getElementById('canvas').offsetLeft; this.y=event.clientY-document.getElementById('canvas').offsetTop; ctx.strokeStyle='#000'; ctx.lineWidth=1; ctx.beginPath(); 弧(this.x,this.y,this.r,0,Math.PI*2,true); ctx.closePath(); ctx.stroke(); };
是的,可以通过javascript和CSS3更改光标的形状和大小。看看这些资源,他们有一些很好的信息让你开始




下面是另一个SO用户()的代码片段


测试
#保持{边距:0自动;宽度:500px;高度:500px;边框:1px实心#000;}
#画布{float:left;}
#顶层{位置:绝对;z索引:1;宽度:500px;高度:500px;光标:十字线;}
var ctx=document.getElementById('canvas').getContext('2d'); 功能跟踪鼠标(事件){ ctx.globalCompositeOperation=“源代码结束”; ctx.clearRect(0,0500500); this.r=25;//圆的半径 这个.x; 这个.y; this.x=event.clientX-document.getElementById('canvas').offsetLeft; this.y=event.clientY-document.getElementById('canvas').offsetTop; ctx.strokeStyle='#000'; ctx.lineWidth=1; ctx.beginPath(); 弧(this.x,this.y,this.r,0,Math.PI*2,true); ctx.closePath(); ctx.stroke(); };
此链接将我们重定向到其他地方,为什么不直接附加图片?使用画布,是的。你试过什么?@void我试过直接展示它,但它说你至少需要10个声望才能发布图片。国际机械师协会sorry@KaiQing老实说,我不知道从哪里开始,我在谷歌上搜索了好几次,但没有找到任何帮助。这个链接正在将我们重定向到其他地方,你为什么不直接附加图片?使用画布,是的。你试过什么?@void我试过直接展示它,但它说你至少需要10个声望才能发布图片。国际机械师协会sorry@KaiQing老实说,我不知道从哪里开始,我在谷歌上搜索了好几次,但没有找到任何帮助我的方法。我已经检查了所有这些,但没有找到任何帮助我更改光标的方法size@BeboIbrahim检查我所做的更新,这应该是您正在寻找的。我已经检查了所有这些,但没有找到任何帮助我更改光标的内容size@BeboIbrahim检查我的更新,这应该是你正在寻找的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8 />
<title>test</title>
<style type="text/css">
#hold { margin:0 auto; width:500px; height:500px; border:1px solid #000; }
#canvas { float:left; }
#top-layer { position:absolute; z-index:1; width:500px; height:500px; cursor:crosshair; }
</style>
</head>
<body>

<div id="hold">

  <canvas id="canvas" width="500" height="500"></canvas>

  <div id="top-layer" onmousemove="trackMouse(event);">
    <ul>
      <li><a href="http://www.google.com">Test Link (takes u to google)</a></li>
      <li><a href="http://www.google.com">Test Link (takes u to google)</a></li>
      <li><a href="http://www.google.com">Test Link (takes u to google)</a></li>
      <li><a href="http://www.google.com">Test Link (takes u to google)</a></li>
      <li><a href="http://www.google.com">Test Link (takes u to google)</a></li>
      <li><a href="http://www.google.com">Test Link (takes u to google)</a></li>
    </ul>
  </div>

</div>

<script type="text/javascript">

var ctx = document.getElementById('canvas').getContext('2d');

function trackMouse(event) {
  ctx.globalCompositeOperation = "source-over";
  ctx.clearRect(0, 0, 500, 500);

  this.r = 25; // Radius of circle
  this.x;
  this.y;

  this.x = event.clientX - document.getElementById('canvas').offsetLeft;
  this.y = event.clientY - document.getElementById('canvas').offsetTop;

  ctx.strokeStyle = '#000';
  ctx.lineWidth = 1;
  ctx.beginPath();
  ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2, true);
  ctx.closePath();
  ctx.stroke();
};

</script>
</body>
</html>