admin管理员组文章数量:1323500
I have created a group using Snap.svg.
shape = paper.rect(225, 50, 100, 50, 10, 10);
text = paper.text(253,82, "text")
myGroup = paper.g(shape, text);
myGroup.click(toggleSelection);
When I actually click the group with my mouse the toggleSelection function is executed. I am unable to figure out how to simulate a click. I've tried myGroup.click() myGroup.events.click() etc.
There doesn't seem to be a built in method to Snap so standard JS is wele!
I have created a group using Snap.svg.
shape = paper.rect(225, 50, 100, 50, 10, 10);
text = paper.text(253,82, "text")
myGroup = paper.g(shape, text);
myGroup.click(toggleSelection);
When I actually click the group with my mouse the toggleSelection function is executed. I am unable to figure out how to simulate a click. I've tried myGroup.click() myGroup.events.click() etc.
There doesn't seem to be a built in method to Snap so standard JS is wele!
Share asked Jan 21, 2015 at 22:04 PhilPhil 971 gold badge2 silver badges10 bronze badges1 Answer
Reset to default 9var event = document.createEvent("SVGEvents");
event.initEvent("click",true,true);
myGroup.dispatchEvent(event);
This will fire an event that you assigned with .on("click") earlier. This is nicer than manually creating a mouse event with Xs and Ys, as that's difficult and is probably fraught with peril given that your objects overlap each other at times.
本文标签: javascriptSimulate click event on an svg groupStack Overflow
版权声明:本文标题:javascript - Simulate click event on an svg group - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742143404a2422682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论