SVG通过jQuery.svg [英] SVG through the jQuery.svg

查看:119
本文介绍了SVG通过jQuery.svg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery svg插件中( http://plugins.jquery.com/project/svg )使用svg从div元素开始执行并在div中创建新的svg对象:

In jQuery svg plugin (http://plugins.jquery.com/project/svg) work with svg is performed starting from div element and creating new svg object inside of div:


将SVG画布附加到具有以下内容的a :

Attach an SVG canvas to a with the following:



$(selector).svg();

是否可以将jquery连接到现有的svg-object?如果是怎么做?

Is it possible to connect with jquery to existing svg-object? If "yes" how to do that?

编辑:
建议提示:

Suggested tip:

<body onload="alert('loaded');testSvg();">
    <div id="div3" style="border: solid 1px black; width:200px; height:100px">
        <svg id="svg3" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>
    </div>

    <script type="text/javascript">
    function testSvg() {
        var svgRootElement = $("#svg3").get();
        var svgWrapper = new $.svg._wrapperClass(svgRootElement);
        svgWrapper.circle(30, 25, 50, { fill: 'red' });
    }

导致错误:


'TypeError:无法获取属性'createElementNS'的值:object为null或undefined'error ...

'TypeError: Unable to get value of the property 'createElementNS': object is null or undefined' error...

为什么?

推荐答案

是的,这是可能的。它描述了这里,虽然它有点难以找到。如果您正在使用内联SVG(例如,您没有使用对象标签或iframe将SVG嵌入到HTML中),则以下内容应该有效:

Yes, it is possible. It's described here, although it's a bit difficult to find. If you're using inline SVG (e.g. you're not embedding SVG into HTML using an object tag, or an iframe), then the following should work:

$(document).ready(function(){
var svgRootElement = $("#myExistingSVGObject");
var svgWrapper = new $.svg._wrapperClass(svgRootElement); // this is the equivalent of what is returned from the call to .svg()
})

这篇关于SVG通过jQuery.svg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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