简体   繁体   中英

Raphael.js undefined variable

I've recently turned to RaphaelJS, due to need of .onclick events on variables painted on a canvas. My problem is, I transformed my whole website to use raphaeljs, but, as I try to run it, it tells me that H (the variable I'm listening onclick to) is undefined.

Here 'sa jsfiddle of the website.

You are assigning H.node.onclick when the DOM is loaded, but H is not initialized until drawbg is called, which happens when you click on the canvas.

You can solve this problem by assigning the event handler after drawbg was called. You should also avoid global variables (such as H ).

您可以在函数drawbg()中初始化变量H,但是在调用此函数之前,请先调用此变量的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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