简体   繁体   English

使用javascript访问内联SVG元素

[英]accessing inline SVG elements with javascript

I'm playing around with SVG and I've hit a wall. 我在玩SVG,碰壁了。

what im trying to do it when you hover over on svg element it will cause another to appear. 当您将鼠标悬停在svg元素上时,即时通讯试图执行的操作将导致另一个显示。

my idea was using javascript to add and remove a "hidden" class when you hover, but its not working, it works on none SVG elements but I can't see why it's not working here. 我的想法是在悬停时使用javascript添加和删除“隐藏的”类,但它不起作用,它无法在SVG元素上使用,但我看不到为什么它在这里不起作用。

<svg xmlns:cc="http://web.resource.org/cc/" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:svg="http://www.w3.org/2000/svg" 
    width="400px"
    height="400px"
    viewBox="0 150 960 900">
<path id="loc36" class="maploc" d="m 352.28954,738.20354 0,140.66609 85.8653,0 0,-140.41399 z"/>
<path id="info36" class="infopanel " d="m 306.42857,896.64787 0,157.85713 539.28572,0 0,-158.57141 z"/>
</svg>

Javascript Java脚本

$("#loc36").hover(function(){
        $('#info36').removeClass('hidden');
    },function(){
        $('#info36').addClass('hidden');
    });

https://jsfiddle.net/atprsteq/ https://jsfiddle.net/atprsteq/

Its works on none SVG elements, like this example http://jsfiddle.net/EzfwV/210/ 它不能在任何SVG元素上工作,例如本例http://jsfiddle.net/EzfwV/210/

Am I just missing something simple here? 我只是在这里想念一些简单的东西吗?

Am I just missing something simple here? 我只是在这里想念一些简单的东西吗?

Yes. 是。

错误消息的屏幕截图

You forgot to include jQuery! 您忘了包括jQuery!

JavaScript设置的屏幕截图

Select jQuery from the "Frameworks & Extensions" menu. 从“框架和扩展”菜单中选择jQuery。

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

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