SVGSVGElement - Web API 接口参考 编辑
该SVGSVGElement
接口提供对<svg>
元素的属性的访问,以及操作它们的方法。此接口还包含各种常用的实用方法,例如矩阵操作和控制可视渲染设备上重绘时间的功能。
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 23.333333333333332%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 140" preserveAspectRatio="xMinYMin meet"><a xlink:href="/wiki/zh-CN/docs/Web/API/EventTarget" target="_top"><rect x="1" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="56" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">EventTarget</text></a><polyline points="111,25 121,20 121,30 111,25" stroke="#D4DDE4" fill="none"/><line x1="121" y1="25" x2="151" y2="25" stroke="#D4DDE4"/><a xlink:href="/wiki/zh-CN/docs/Web/API/Node" target="_top"><rect x="151" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="188.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Node</text></a><polyline points="226,25 236,20 236,30 226,25" stroke="#D4DDE4" fill="none"/><line x1="236" y1="25" x2="266" y2="25" stroke="#D4DDE4"/><a xlink:href="/wiki/zh-CN/docs/Web/API/Element" target="_top"><rect x="266" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="303.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Element</text></a><polyline points="341,25 351,20 351,30 341,25" stroke="#D4DDE4" fill="none"/><line x1="351" y1="25" x2="381" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/wiki/zh-CN/docs/Web/API/SVGElement" target="_top"><rect x="381" y="1" width="100" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="431" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">SVGElement</text></a><polyline points="481,25 491,20 491,30 481,25" stroke="#D4DDE4" fill="none"/><line x1="491" y1="25" x2="499" y2="25" stroke="#D4DDE4"/><line x1="499" y1="25" x2="499" y2="90" stroke="#D4DDE4"/><line x1="499" y1="90" x2="482" y2="90" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/wiki/zh-CN/docs/Web/API/SVGGraphicsElement" target="_top"><rect x="301" y="65" width="180" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="391" y="94" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">SVGGraphicsElement</text></a><polyline points="301,89 291,84 291,94 301,89" stroke="#D4DDE4" fill="none"/><line x1="291" y1="89" x2="261" y2="89" stroke="#D4DDE4"/><a xlink:href="/wiki/zh-CN/docs/Web/API/SVGSVGElement" target="_top"><rect x="131" y="65" width="130" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="196" y="94" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">SVGSVGElement</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
属性
此接口还从其父 SVGGraphicsElement
继承属性,并且还实现 SVGZoomAndPan
, SVGFitToViewBox
和 WindowEventHandlers
中的属性。
SVGSVGElement.x
只读-
SVGAnimatedLength
对应于给定<svg>
元素的x
属性 SVGSVGElement.y
只读SVGAnimatedLength
对应于给定<svg>
元素的y
属性。SVGSVGElement.width
只读SVGAnimatedLength
对应于给定<svg>
元素的width
属性。SVGSVGElement.height
只读SVGAnimatedLength
对应于给定<svg>
元素的height
属性。SVGSVGElement.contentScriptType
SVGAnimatedLength
对应于给定<svg>
元素的contentScriptType
属性。SVGSVGElement.contentStyleType
SVGAnimatedLength
对应于给定<svg>
元素的contentStyleType
属性。SVGSVGElement.viewport
- 一个
SVGRect
,包含与给定<svg>
元素对应的视口(隐式或显式)的位置和大小。当浏览器实际呈现内容时,位置和大小值表示呈现时的实际值。位置和大小值是父元素坐标系中的无单位值。如果不存在父元素(即<svg>
元素表示文档树的根),如果此SVG文档作为另一文档的一部分嵌入(例如,通过HTML object element),然后位置和大小是父文档坐标系中的无单位值。(如果父级使用CSS或XSL布局, SVGSVGElement.pixelUnitToMillimeterX
- 一个浮点数,表示沿视口x轴的像素单位(由CSS2定义)的大小,表示70dpi到120dpi范围内的某个单位,并且在支持此功能的系统上,可能实际上与特征匹配目标媒体。在不可能知道像素大小的系统上,提供合适的默认像素大小。
SVGSVGElement.pixelUnitToMillimeterY
- 浮点数,表示沿视口y轴的像素单位大小。
SVGSVGElement.screenPixelToMillimeterX
- DOM级别2中的用户界面(UI)事件指示给定UI事件发生的屏幕位置。当浏览器实际知道“屏幕单元”的物理尺寸时,此浮动属性将表示该信息; 否则,用户代理将提供合适的默认值,例如.28mm。
SVGSVGElement.screenPixelToMillimeterY
- 沿着视口的y轴的屏幕像素的对应大小。
SVGSVGElement.useCurrentView
- 当前最内层SVG文档片段的初始视图(即放大和平移之前)可以是“标准”视图,即基于
<svg>
元素的属性,例如viewBox
)或“自定义”视图(即指向特定<view>
或其他元素的超链接)。如果初始视图是“标准”视图,则此属性为false
。如果初始视图是“自定义”视图,则此属性为true
。 SVGSVGElement.currentView
SVGViewSpec
定义当前最里面的SVG文档片段的初始视图(即,放大和平移之前)。意义取决于具体情况:如果初始视图是“标准”视图,则:viewBox
,preserveAspectRatio
和currentView
中的zoomAndPan
的值将与值匹配对于SVGSVGElement
直接打开的相应DOM属性- }
currentView
中的transform
和viewTarget
的值将为null
<view>
元素的链接,那么:- 在
currentView
中viewBox
,preserveAspectRatio
和zoomAndPan
的值将对应于给定<view>
元素的相应属性 - }
currentView
中的transform
和viewTarget
的值将为null
<view>
}之外的其他元素,则:viewBox
,preserveAspectRatio
和currentView
中的zoomAndPan
的值将与值匹配对于SVGSVGElement
直接用于最近祖先<svg>
元素的相应DOM属性currentView
中transform
的值将为nullcurrentView
中的viewTarget
将代表链接的目标
- the values for
viewBox
,preserveAspectRatio
,zoomAndPan
,transform
andviewTarget
withincurrentView
will correspond to the values from the SVG view specification fragment identifier
SVGSVGElement.currentScale
- On an outermost
<svg>
element, this float attribute indicates the current scale factor relative to the initial view to take into account user magnification and panning operations. DOM attributescurrentScale
andcurrentTranslate
are equivalent to the 2x3 matrix[a b c d e f] = [currentScale 0 0 currentScale currentTranslate.x currentTranslate.y]
. If "magnification" is enabled (i.e.,zoomAndPan="magnify"
), then the effect is as if an extra transformation were placed at the outermost level on the SVG document fragment (i.e., outside the outermost<svg>
element). SVGSVGElement.currentTranslate
只读- An
SVGPoint
representing the translation factor that takes into account user "magnification" corresponding to an outermost<svg>
element. The behavior is undefined for <svg> elements that are not at the outermost level.
Methods
This interface also inherits methods from its parent, SVGGraphicsElement
and also implements the ones from SVGZoomAndPan
, SVGFitToViewBox
, and WindowEventHandlers
.
SVGSVGElement.suspendRedraw()
Takes a time-out value which indicates that redraw shall not occur until:
the corresponding unsuspendRedraw() call has been made, an unsuspendRedrawAll() call has been made, or its timer has timed out.In environments that do not support interactivity (e.g., print media), then redraw shall not be suspended. Calls to
suspendRedraw()
andunsuspendRedraw()
should, but need not be, made in balanced pairs.To suspend redraw actions as a collection of SVG DOM changes occur, precede the changes to the SVG DOM with a method call similar to:
suspendHandleID = suspendRedraw(maxWaitMilliseconds);
and follow the changes with a method call similar to:
unsuspendRedraw(suspendHandleID);
Note that multiple suspendRedraw calls can be used at once and that each such method call is treated independently of the other suspendRedraw method calls.
SVGSVGElement.unsuspendRedraw()
- Cancels a specified
suspendRedraw()
by providing a unique suspend handle ID that was returned by a previoussuspendRedraw()
call. SVGSVGElement.unsuspendRedrawAll()
- Cancels all currently active
suspendRedraw()
method calls. This method is most useful at the very end of a set of SVG DOM calls to ensure that all pendingsuspendRedraw()
method calls have been cancelled. SVGSVGElement.forceRedraw()
- In rendering environments supporting interactivity, forces the user agent to immediately redraw all regions of the viewport that require updating.
SVGSVGElement.pauseAnimations()
- Suspends (i.e., pauses) all currently running animations that are defined within the SVG document fragment corresponding to this
<svg>
element, causing the animation clock corresponding to this document fragment to stand still until it is unpaused. SVGSVGElement.unpauseAnimations()
- Unsuspends (i.e., unpauses) currently running animations that are defined within the SVG document fragment, causing the animation clock to continue from the time at which it was suspended.
SVGSVGElement.animationsPaused()
- Returns true if this SVG document fragment is in a paused state.
SVGSVGElement.getCurrentTime()
- Returns the current time in seconds relative to the start time for the current SVG document fragment. If getCurrentTime is called before the document timeline has begun (for example, by script running in a
<script>
element before the document's SVGLoad event is dispatched), then 0 is returned. SVGSVGElement.setCurrentTime()
- Adjusts the clock for this SVG document fragment, establishing a new current time. If
setCurrentTime
is called before the document timeline has begun (for example, by script running in a<script>
element before the document's SVGLoad event is dispatched), then the value of seconds in the last invocation of the method gives the time that the document will seek to once the document timeline has begun. SVGSVGElement.getIntersectionList()
- Returns a
NodeList
of graphics elements whose rendered content intersects the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-events
processing. SVGSVGElement.getEnclosureList()
- Returns a
NodeList
of graphics elements whose rendered content is entirely contained within the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-events
processing. SVGSVGElement.checkIntersection()
- Returns
true
if the rendered content of the given element intersects the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-events
processing. SVGSVGElement.checkEnclosure()
- Returns
true
if the rendered content of the given element is entirely contained within the supplied rectangle. Each candidate graphics element is to be considered a match only if the same graphics element can be a target of pointer events as defined inpointer-events
processing. SVGSVGElement.deselectAll()
- Unselects any selected objects, including any selections of text strings and type-in bars.
SVGSVGElement.createSVGNumber()
- Creates an
SVGNumber
object outside of any document trees. The object is initialized to a value of zero. SVGSVGElement.createSVGLength()
- Creates an
SVGLength
object outside of any document trees. The object is initialized to a value of zero user units. SVGSVGElement.createSVGAngle()
- Creates an
SVGAngle
object outside of any document trees. The object is initialized to a value of zero degrees (unitless). SVGSVGElement.createSVGPoint()
- Creates an
SVGPoint
object outside of any document trees. The object is initialized to the point (0,0) in the user coordinate system. SVGSVGElement.createSVGMatrix()
- Creates an
SVGMatrix
object outside of any document trees. The object is initialized to the identity matrix. SVGSVGElement.createSVGRect()
- Creates an
SVGRect
object outside of any document trees. The object is initialized such that all values are set to 0 user units. SVGSVGElement.createSVGTransform()
- Creates an
SVGTransform
object outside of any document trees. The object is initialized to an identity matrix transform (SVG_TRANSFORM_MATRIX
). SVGSVGElement.createSVGTransformFromMatrix()
- Creates an
SVGTransform
object outside of any document trees. The object is initialized to the given matrix transform (i.e.,SVG_TRANSFORM_MATRIX
). The values from the parameter matrix are copied, the matrix parameter is not adopted asSVGTransform::matrix
. SVGSVGElement.getElementById()
- Searches this SVG document fragment (i.e., the search is restricted to a subset of the document tree) for an Element whose id is given by elementId. If an Element is found, that Element is returned. If no such element exists, returns null. Behavior is not defined if more than one element has this id.
Specifications
Specification | Status | Comment |
---|---|---|
Scalable Vector Graphics (SVG) 2 SVGSVGElement | Candidate Recommendation | Replaced the inheritance from SVGElement by SVGGraphicsElement , removed the implemented interfaces SVGTests , SVGLangSpace , SVGExternalResourcesRequired , SVGStylable , SVGLocatable , DocumentEvent , ViewCSS , and DocumentCSS and added implemented interface WindowEventHandlers . |
Scalable Vector Graphics (SVG) 1.1 (Second Edition) SVGSVGElement | Recommendation | Initial definition |
Browser compatibility
BCD tables only load in the browser
此页面上的兼容性表是根据结构化数据生成的。如果您想为数据做出贡献,请查看https://github.com/mdn/browser-compat-data并向我们发送拉取请求。也可以看看
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论