带ID的拉斐尔纸 [英] Raphael paper with id
问题描述
我遇到的情况是要在页面上添加多篇论文.我已经在每个对象上绘制了一些rect和path对象.我知道如何为每个这样的对象赋予ID,但是我还没有看到向纸张本身添加ID的任何示例.我需要在论文中单击rect时更改对象.为此,我想清除旧对象并绘制新对象.问题是我正在为纸张重用变量.因此,该变量包含对我不想要的最新论文的引用.由于所有这些,我想知道是否可以为每个ID附加一个ID并检索纸张然后使用它. 欢迎任何建议. 卡维塔(Kavita)
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
我无法从已单击的形状中获取纸质对象!! this.paper,$(this).paper不起作用. 任何帮助表示赞赏...
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...
推荐答案
看看这个 fiddle .如果您要使用
Take a look at this fiddle. If you are setting up the event handler using something like
$(object.node).mouseover(function() {...})
在函数中引用this
时,它引用的是DOM节点,而不是Raphael对象.因此,您无法访问Raphael的属性或方法.我能够做到这一点的唯一方法是通过在事件数据中传入Raphael对象,如下所示:
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();
});
这篇关于带ID的拉斐尔纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!