【发布时间】: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。拉斐尔没有锻炼