带有 id 的拉斐尔纸

发布于 2024-11-27 13:37:28 字数 294 浏览 9 评论 0原文

我遇到过这样的情况:我要向页面添加多篇论文。我在每个对象上绘制了某些矩形和路径对象。我知道如何为每个这样的对象提供 id,但我还没有看到任何向论文本身添加 id 的示例。我需要更改纸张内矩形的单击事件的对象。为此,我想清除旧对象并绘制新对象。问题是我正在重复使用论文的变量。因此,该变量包含对最新论文的引用,但这不是我想要的。由于这一切,我想知道是否可以为每张纸附上一个 ID 并检索纸张,然后使用它。 欢迎任何建议。 卡维塔

嗨, 我无法从已单击的形状中获取纸质对象! this.paper、$(this).paper 不起作用。 任何帮助将不胜感激...

I have a situation where I am adding multiple papers to my page. I have drawn certain rect and path objects on each. I know how I can give id to each such object, but i haven't seen any example for adding an id to the paper itself. I need to change the objects on click event of a rect within the paper. For this I want to clear the old objects and draw new ones. The problem is that i am reusing the variable for the paper. Hence the variable contains a reference to the most recent paper which is not the one i want. Due to all this I was wondering if I could attach an id to each and retrieve the paper and then use it.
Any suggestions are welcome.
Kavita

Hi,
I am unable to get the paper object from the shape that has been clicked!!
this.paper, $(this).paper dont work.
Any help is appreciated...

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

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

发布评论

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

评论(1

り繁华旳梦境 2024-12-04 13:37:28

看看这个fiddle。 设置事件处理程序

$(object.node).mouseover(function() {...})

如果您使用类似于在函数中引用 this 的方式 ,则它引用的是 DOM 节点,而不是 Raphael 对象。因此,您无法访问 Raphael 的属性或方法。我能够让它工作的唯一方法是在事件数据中传入 Raphael 对象,如下所示:

$(object2.node).mouseover({rObj: object2},
                           function (e) {
                               e.data.rObj.paper.clear();
                           });

Take a look at this fiddle. If you are setting up the event handler using something like

$(object.node).mouseover(function() {...})

when you refer to this in the function, it refers to the DOM node, not the Raphael object. Consequently, you cannot access Raphael's properties or methods. The only way I have been able to get this to work is by passing in the Raphael object in the event data like so:

$(object2.node).mouseover({rObj: object2},
                           function (e) {
                               e.data.rObj.paper.clear();
                           });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文