通过javascript获取原始SVG viewBox [英] Obtaining an original SVG viewBox via javascript

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

问题描述

我们的系统通过AJAX以编程方式将SVG文件加载到HTML中。典型的SVG文件以:

Our system loads SVG files programmatically into HTML via AJAX. A typical SVG file begins with:

 <svg xmlns='http://www.w3.org/2000/svg' viewBox='0,0 65415,41616' xml:space='preserve' height='50.000cm'  width='50.000cm' xmlns:xlink='http://www.w3.org/1999/xlink

但奇怪的是,在JavaScript中似乎无法从SVG DOM中获取此viewBox - 无论是作为字符串,或作为一组值。例如,在Mozilla下,firebug报告svg节点有我们指定的6个属性中的5个 - 即:xmlns,xml:space,height,width和xmlns:xlink。但是此列表中明显缺少 ViewBox

But strangely in JavaScript there seems to be no way of getting this 'viewBox' back from the SVG DOM - either as a string, or as a set of values. Under Mozilla, for example, firebug reports that the svg node has 5 of the 6 attributes we specifiy - namely: xmlns, xml:space, height, width and xmlns:xlink. But ViewBox is conspicuously missing from this list.

无论如何以编程方式检索此值? - 它在SVG DOM中的位置? (我们不能介绍第三方库。)

Is there anyway to programmatically retrieve this value? - where is it in the SVG DOM? (We cannot introduce 3rd party libraries).

推荐答案

你想看一下 SVGFitToViewBox 界面,指定 viewBox 属性。 svg 元素的界面, SVGSVGElement ,扩展了该界面,因此可能是您正在寻找的属性。

You'll want to take a look at the SVGFitToViewBox interface, which specifies the viewBox property. The interface for svg elements, SVGSVGElement, extends that interface, so that might be the property you're looking for.

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

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