如何在双击时添加新点(图像)?
我有 javascript 函数(使用 Raphael),单击选择区域。我需要添加双击时的新功能:
- 添加新图像(象征点的小图像)
- 在此图像(点)旁边添加一些文本字段,以便用户可以向该点添加描述在
- 图像和文本旁边添加删除按钮场地。这样,如果用户想要删除它,他可以。它应该使用文本字段删除这个全新的点(图像)
- 我还需要知道这个新点的坐标,以便我可以保存它
这是我的 javascript 函数的代码:
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var R = Raphael("paper", 500, 500);
var attr = {
fill: "#EEC7C3",
stroke: "#E0B6B2",
"stroke-width": 1,
"stroke-linejoin": "round"
};
var area = {};
area.Element1 = R.path("...").attr(attr);
area.Element2 = R.path("...").attr(attr);
...
area.Element63 = R.path("...").attr(attr);
var current = null;
for (var state in area) {
area[state].color = Raphael.getColor();
(function (st, state) {
st[0].state = 0;
st[0].style.cursor = "pointer";
st[0].onmouseover = function () {
current && area[current].animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500) && (document.getElementById(current).style.display = "");
st.animate({ fill: st.color, stroke: "#ccc" }, 500);
st.toFront();
R.safari();
document.getElementById(state).style.display = "block";
current = state;
};
st[0].onmouseout = function () {
if (this.state == 0)
st.animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500);
else
st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
st.toFront();
R.safari();
};
st[0].onclick = function () {
st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
st.toFront();
if (this.state == 0)
this.state = 1;
else
this.state = 0;
R.safari();
};
})(area[state], state);
}
};
</script>
我不是 javascript 程序员,所以我真的不知道甚至知道从哪里开始。因此,非常感谢这里的任何帮助!
I have javascript function (that uses Raphael) that on click select area. And I need to add new function that on double click:
- add new image (small image that symbolizes point)
- add some text field next to this image (point) so that user could add description to this point
- add remove button next to image and text field. So that if user woluld like to remove it he could. It should remove this whole new point(image) with text field
- I need to also know cordinates of this new point, so that I could save it
Here is code of my javascript function:
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var R = Raphael("paper", 500, 500);
var attr = {
fill: "#EEC7C3",
stroke: "#E0B6B2",
"stroke-width": 1,
"stroke-linejoin": "round"
};
var area = {};
area.Element1 = R.path("...").attr(attr);
area.Element2 = R.path("...").attr(attr);
...
area.Element63 = R.path("...").attr(attr);
var current = null;
for (var state in area) {
area[state].color = Raphael.getColor();
(function (st, state) {
st[0].state = 0;
st[0].style.cursor = "pointer";
st[0].onmouseover = function () {
current && area[current].animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500) && (document.getElementById(current).style.display = "");
st.animate({ fill: st.color, stroke: "#ccc" }, 500);
st.toFront();
R.safari();
document.getElementById(state).style.display = "block";
current = state;
};
st[0].onmouseout = function () {
if (this.state == 0)
st.animate({ fill: "#EEC7C3", stroke: "#E0B6B2" }, 500);
else
st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
st.toFront();
R.safari();
};
st[0].onclick = function () {
st.animate({ fill: "#C05219", stroke: "#E0B6B2" }, 500);
st.toFront();
if (this.state == 0)
this.state = 1;
else
this.state = 0;
R.safari();
};
})(area[state], state);
}
};
</script>
I am not a javascript programmer so I don't really even know where to start. So any help here is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法使用比 Raphael 更简单的 javascipt 让它工作。这是代码:
I have manage to make it work using more simple javascipt than Raphael. Here is code:
你的需求不明确,尤其是RaphaelJS的使用。这是使用 RaphaelJS 添加图像的方法。
HTML
Javascript
对于按钮和所有可以使用 HTML 元素,并将其放置在 RaphaelJS svg 上的 div target 中。
Your requirement is not clear, especially the use of RaphaelJS. This is how you can add an image using RaphaelJS.
HTML
Javascript
For button and all you can use HTML elements, and place it in the div target over RaphaelJS svg.