简体   繁体   English

移动时在fabric.js中获取鼠标position

[英]get mouse position in fabric.js while moving

I'd like to get the mouse position while moving.我想在移动时拿到鼠标 position。

 var canvas = new fabric.Canvas('c1'); canvas.on('mouse:up', function (e) { getMouse(e); }); function getMouse(e) { console.log(eeclientX,eeclientY); }
 canvas { border: 1px solid red; }
 <canvas id="c1" width="300" height="300"></canvas> <script src="https://unpkg.com/fabric@4.6.0/dist/fabric.js"></script>

This gets me the position of the mouse when I click.当我点击时,这让我得到了鼠标的 position。 How do I get mouse position while moving the mouse?如何在移动鼠标时获得鼠标 position?

A quick peek at Canvas docs suggest replacing mouse:up with mouse:move should be what you're after.快速浏览Canvas 文档建议将mouse:up替换为mouse:move应该是您所追求的。

See it working:看到它工作:

 const canvas = new fabric.Canvas('c1'); const getMouse = ({ e }) => { console.log(e.clientX, e.clientY); } canvas.on('mouse:move', getMouse);
 canvas { border: 1px solid red; }
 <canvas id="c1" width="300" height="300"></canvas> <script src="https://unpkg.com/fabric@4.6.0/dist/fabric.js"></script>

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

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