如何使用jQuery选择Raphael SVG标签? [英] How to select a raphael svg tag with jQuery?

查看:167
本文介绍了如何使用jQuery选择Raphael SVG标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Raphael还是很陌生,在文档中也很迷茫...

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

我想通过jQuery操作Raphael对象:

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

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

路径是Raphael生成的路径,jQuery似乎无法选择此svg标记.

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 ?

谢谢;)

推荐答案

感谢Jacktheripper的帮助,这是一个解决方案.

Here is a solution, thanks to jacktheripper help.

jQuery无法直接操纵raphael对象;我们需要使用其对DOM的引用(其节点).

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

因此,jQuery处理程序需要Raphael对象名称.在此示例中,我使用rel标签存储raphael对象的名称.

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

这篇关于如何使用jQuery选择Raphael SVG标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆