Raphael paper with id

眉间皱痕 提交于 2020-01-16 20:34:30

问题


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...


回答1:


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();
                           });


来源:https://stackoverflow.com/questions/6908242/raphael-paper-with-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!