How to select a raphael svg tag with jQuery?

2019-06-11 00:33发布

I'm quite new to Raphael, and quite lost too in its documentation...

I'd like to manipulate a Raphael object through jQuery:

$(".handle").hover(
               function() {
                     $("path[rel='"+$(this).attr('rel')+"']").addClass("pathhover");
               }, 
               function() {
                    $("path").removeClass("pathhover");
               }
            );

Path is a Raphael-generated path, and jQuery does not seem to be able to select this svg tag.

Would you have an idea how to achieve this ?

Thanks ;)

2条回答
Emotional °昔
2楼-- · 2019-06-11 01:12

Here is a solution, thanks to jacktheripper help.

The raphael object can't be manipulated directly by jQuery; we need to use its reference to the DOM (its node).

Therefore, the jQuery handler needs the Raphael object name. In this example, I use the rel tag to store the name of the raphael object.

$(".handle").hover(
               function() {
                     var path=eval($(this).attr('rel'));
                     path.node.setAttribute("class","pathhover");
               }, 
               function() {
                    var path=eval($(this).attr('rel'));
                    path.node.removeAttribute("class","pathhover");
               }
            );
查看更多
你好瞎i
3楼-- · 2019-06-11 01:29

Much easier to use the native hover methods from Raphael http://irunmywebsite.com/raphael/additionalhelp.php?q=raphaelevents Using node can yield incomplete results

查看更多
登录 后发表回答