【问题标题】:draw line on mouse drag in raphael js在raphael js中鼠标拖动画线
【发布时间】:2015-09-22 20:52:05
【问题描述】:

这是我尝试过的:

 <!doctype html>
    <html>
        <head>
            <title>Editor</title>
            <meta http-equiv="x-ua-compatible" content="ie=9"/>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.4/raphael-min.js"></script>
            <script type="text/javascript" src="<%=request.getContextPath()%>/connector.js"></script>
            <link rel="stylesheet" href="<%=request.getContextPath()%>/style.css" />

            <script type="text/javascript">
                window.onload = function ()
        {
            var paper = new Raphael(Raphael("container", "100%", "100%"));
            var line = paper.path();
            var start = function (x, y) {
                this.ox = this.attr("x");
                this.oy = this.attr("y");
                var line = paper.path("M", this.ox, this.oy);
            },
                    move = function (dx, dy) {
                        this.attr({
                            x: this.ox + dx,
                            y: this.oy + dy
                        });
                       paper.path("L",x,y);
                    },
                    up = function () {
                        this.animate({
                            opacity: 0
                        }, 500);
                    };
                    paper.set(line).drag(move, start, up);
        };
            </script>
        </head>
        <body>
            <div id="container">
                <div id="header" style="margin-bottom: 0;">
                    <h1 id="title">Editor</h1>
                    <div id="footer"></div>
                </div>
            </div>
        </body>
    </html>

这是现场演示:https://jsbin.com/giqufilusu/1/edit?html,output

我不知道为什么它不起作用。是否存在语法问题或我没有正确编码。网上有一些例子,但大多数使用 jquery + raphael js 在鼠标事件上画线,但我想用 raphael 的drag() 方法绘制。我该如何解决这个问题?

【问题讨论】:

  • 不知道你为什么要调用'line()',这是从哪里来的?
  • 我想要的是这个:jsfiddle.net/rRtAq/9358 我尝试了这个例子,有没有 jquery,但没有运气。
  • 更新了问题
  • 无论如何我都会尝试使用paper js。拉斐尔没有锻炼

标签: svg raphael


【解决方案1】:

我不知道我说的对不对。

我猜this 是你想要达到的目标?

您仅在 start 函数的范围内定义了 line 变量。要调整该行,您需要使其可用于所有功能。 jsBin 是一种快速而肮脏的方法,它应该会提示您如何使用 Raphael 进行此线条绘制。

【讨论】:

  • 线应该不用圆圈来画
  • 那是什么意思?
  • 现在在移动圆时画线(在 jsbin 中),但我想只在移动鼠标时画线
猜你喜欢
  • 2019-04-06
  • 2014-04-26
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多