拉斐尔·JS。两个形状之间的橡皮筋路径

发布于 2024-12-20 00:25:15 字数 431 浏览 5 评论 0原文

任何人都有在 Raphael 中在两个形状之间绘制橡皮筋样式路径的示例代码。

我在 如何绘制矢量中看到了一些有关逐步绘制路径的问题循序渐进的路径? (Raphael.js)

但我的要求是能够单击一个形状并将鼠标移动到另一个形状,并且当鼠标移动时,应该有一条像橡皮筋一样跟随鼠标的线条路径。一旦单击第二个形状,线条路径就必须被锁定。

我尝试了 Joint.js http:// www.jointjs.com/ 与Raphael,但它可以画线,但不能交互。

Anyone has sample code for drawing a rubber band style path between two shapes in Raphael.

I saw few questions around drawing path progressively at How to draw a vector path progressively? (Raphael.js)

But my requirement is to be able to click on one shape and move the mouse to the other shape and while the mouse moves, there should be a line path following the mouse like a rubber band. Once the click happens on the second shape the line path has to be locked in.

I tried the Joint.js http://www.jointjs.com/ with Raphael but it can draw lines but not interactively.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阪姬 2024-12-27 00:25:15

以下是入门的基本代码:

var w = window.innerWidth;
var h = window.innerWidth;
var paper = Raphael(0, 0, w, h);
var nodes = paper.set();

var circle1 = paper.circle(w/8, h/3, w/16)
    .attr({fill: "#000"})
    .click(line);
var circle2 = paper.circle(w - w/8, h/3, w/16).attr({fill: "#000"})
    .attr({fill: "#000"})
    .click(line);


function line() {
  var band = paper.path("M 0 0").attr({"stroke-width": 5})
  band.node.style.pointerEvents = "none";
  dimensions = this.getBBox();
  var x = dimensions.x + dimensions.width/2;
  var y = dimensions.y + dimensions.height/2;
  if (!window.onmousemove) {
    window.onmousemove = function(e){
        band.attr({path: "M " + x + " " + y + "L " + e.x + " " + e.y});
    }
  }
  else {
     window.onmousemove = null;
  }
}

您可以在此处查看演示:http://jsfiddle.net/57myn/

Here is the basic code to get you started:

var w = window.innerWidth;
var h = window.innerWidth;
var paper = Raphael(0, 0, w, h);
var nodes = paper.set();

var circle1 = paper.circle(w/8, h/3, w/16)
    .attr({fill: "#000"})
    .click(line);
var circle2 = paper.circle(w - w/8, h/3, w/16).attr({fill: "#000"})
    .attr({fill: "#000"})
    .click(line);


function line() {
  var band = paper.path("M 0 0").attr({"stroke-width": 5})
  band.node.style.pointerEvents = "none";
  dimensions = this.getBBox();
  var x = dimensions.x + dimensions.width/2;
  var y = dimensions.y + dimensions.height/2;
  if (!window.onmousemove) {
    window.onmousemove = function(e){
        band.attr({path: "M " + x + " " + y + "L " + e.x + " " + e.y});
    }
  }
  else {
     window.onmousemove = null;
  }
}

You can check out a demo here: http://jsfiddle.net/57myn/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文