简体   繁体   English

Raphael.js如何在路径上找到点击位置?

[英]Raphael.js how to find click position on a path?

Is there any way to access a click-on-path coordinates? 有没有办法访问点击路径坐标? And one other: is possible to find out whitch is the previous closest corner on the path? 还有一个:有可能发现whitch是路径上最近的一个角落吗?

I was read this, but not so helpful: Raphaeljs: accessing the relative postion of a click on a closed path 我读过这篇文章,但不是那么有用: Raphaeljs:访问关闭路径上点击的相对位置

Thanks for yout time! 谢谢你的时间!

Are you looking for something like this: 你在寻找这样的东西:

var paper = Raphael(10, 10, 400, 400);

var path = paper.path("M0 0L10 100L50 100L100 70").attr({"stroke": "#000", "stroke-width": "3"});
path.click(function(event) {
    console.log(this);
    console.log(event.x, event.y);
});

http://jsfiddle.net/sLmHd/2/ http://jsfiddle.net/sLmHd/2/

Edit 编辑

I only made a start for you. 我只是为你做了一个开始。 This is a way, not the only way. 这是一种方式,而不是唯一的方式。

I created an object with 2 arrays. 我用2个数组创建了一个对象。 x and y. x和y。

Every click I add the point. 每次点击我都会添加点数。 (You need to check on what index you want to push the point) Also you need to check what the closes corner is. (您需要检查要推送的索引)还需要检查关闭角是什么。 This could be helpfull 这可能会有所帮助

I hope this will help you: http://jsfiddle.net/fvtPN/ 我希望这会对你有所帮助: http//jsfiddle.net/fvtPN/

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

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