简体   繁体   English

如何使用jQuery触发RaphaelJS Element.click()?

[英]How to trigger RaphaelJS Element.click() with jquery?

I am having problems with triggering RaphaelJS's Element.click() with jquery. 我在用jquery触发RaphaelJS的Element.click()时遇到问题。 What I am trying to do is simulating with jquery that the Element.node was clicked and what I am expecting is that Raphael will delegate the click treatment to the previously defined Element.click() method. 我想做的是用jquery模拟Element.node被单击,并且我期望Raphael将单击处理委托给先前定义的Element.click()方法。

In some circumstances I will need to trigger Raphael's Elements event handlers with code somehow using my Element instance. 在某些情况下,我将需要使用我的Element实例以代码触发Raphael的Elements事件处理程序。

In order to simplify my problem, I created a plnkr with just the code that does not work for me. 为了简化我的问题,我创建了一个plnkr,其中包含的代码对我不起作用。 So here is the example: http://plnkr.co/edit/AuSuq1RG6cWpqH2GEzcN?p=preview 因此,这里是示例: http : //plnkr.co/edit/AuSuq1RG6cWpqH2GEzcN?p=preview

What I expect of the code is that after $(r.getById("square").node).trigger("click"); 我期望的代码是在$(r.getById("square").node).trigger("click"); (I have also tried using $(r.getById("square").node).click() ) is executed, myRectangle.click(function() {...} will be called and the heading on the result page will be changed to "The rectangle was clicked!". As you can see this does not happen. However clicking on the shape is working fine. (我也尝试过使用$(r.getById("square").node).click() ),将调用myRectangle.click(function() {...} ,结果页上的标题将更改为“单击了矩形!”。您可以看到这不会发生,但是单击形状效果很好。

Does anyone know what do I miss in this small piece of code? 有谁知道我在这小段代码中错过了什么? How to make such manipulation work? 如何使这种操纵工作?

Thanks! 谢谢!

After I worked around my initial problem so I can finish what I did start, now I found a helpful kinda-solution to the problem that might help others that come across my topic. 在解决了最初的问题后,我可以完成我的工作,现在,我找到了一个有用的解决方案,可以帮助其他人解决我的问题。 What is written in the topic works and worth considering to be adopted as solution. 本主题中编写的内容有效,值得考虑将其用作解决方案。 It do look a bit hacky, but to be honest many things in JS do so. 它看起来确实有点古怪,但是老实说,JS中的许多事情都是这样做的。 So here is the link, hope it can be helpful to someone someday :) - Triggering Raphael events externally 因此,这里是链接,希望有一天对某人有所帮助:)-从外部触发Raphael事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM