SVGTransformList
defines a list of
SVGTransform
对象。
An
SVGTransformList
object can be designated as read only, which means that attempts to modify the object will result in an exception being thrown.
注意:
Starting in
Gecko 9.0
,the
SVGTransformList
DOM interface is now indexable and can be accessed like Arrays
| Also implement | None |
|---|---|
| 方法 |
|
| 特性 |
|
| Normative document | SVG 1.1 (2nd Edition) |
| 名称 | 类型 | 描述 |
|---|---|---|
numberOfItems
|
unsigned long | The number of items in the list. |
length
|
unsigned long | The number of items in the list. |
| Name & Arguments | 返回 | 描述 |
|---|---|---|
clear
()
|
void
|
Clears all existing current items from the list, with the result being an empty list. Exceptions:
|
initialize
(in
|
SVGTransform
|
Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter. If the inserted item is already in a list, it is removed from its previous list before it is inserted into this list. The inserted item is the item itself and not a copy. The return value is the item inserted into the list. Exceptions:
|
getItem
(in unsigned long
index
)
|
SVGTransform
|
Returns the specified item from the list. The returned item is the item itself and not a copy. Any changes made to the item are immediately reflected in the list. The first item is number 0. Exceptions:
|
insertItemBefore
(in
|
SVGTransform
|
Inserts a new item into the list at the specified position. The first item is number 0. If
newItem
is already in a list, it is removed from its previous list before it is inserted into this list. The inserted item is the item itself and not a copy. If the item is already in this list, note that the index of the item to insert before is before the removal of the item. If the
index
is equal to 0, then the new item is inserted at the front of the list. If the index is greater than or equal to
numberOfItems
, then the new item is appended to the end of the list.
Exceptions:
|
replaceItem
(in
|
SVGTransform
|
Replaces an existing item in the list with a new item. If
newItem
is already in a list, it is removed from its previous list before it is inserted into this list. The inserted item is the item itself and not a copy. If the item is already in this list, note that the index of the item to replace is before the removal of the item.
Exceptions:
|
removeItem
(in unsigned long
index
)
|
SVGTransform
|
Removes an existing item from the list. Exceptions:
|
appendItem
(in
|
SVGTransform
|
Inserts a new item at the end of the list. If
newItem
is already in a list, it is removed from its previous list before it is inserted into this list. The inserted item is the item itself and not a copy.
Exceptions:
|
createSVGTransformFromMatrix
(in
|
SVGTransform
|
创建
SVGTransform
object which is initialized to transform of type
SVG_TRANSFORM_MATRIX
and whose values are the given matrix. The values from the parameter matrix are copied, the matrix parameter is not adopted as
SVGTransform::matrix
.
|
consolidate
()
|
SVGTransform
|
Consolidates the list of separate
SVGTransform
objects by multiplying the equivalent transformation matrices together to result in a list consisting of a single
SVGTransform
object of type
SVG_TRANSFORM_MATRIX
. The consolidation operation creates new
SVGTransform
object as the first and only item in the list. The returned item is the item itself and not a copy. Any changes made to the item are immediately reflected in the list.
Exceptions:
|
In this example we create a function that will apply three different transformations to the SVG element that has been clicked on. In order to do this we create a separate
SVGTransform
object for each transformation -- such as
translate
,
rotate
,和
scale
. We apply multiple transformation by appending the transform object to the
SVGTransformList
associated with an SVG element.
<svg id="my-svg" viewBox="0 0 300 280"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Example showing how to transform svg elements that using SVGTransform objects</desc>
<script type="application/ecmascript"> <![CDATA[
function transformMe(evt) {
// svg root element to access the createSVGTransform() function
var svgroot = evt.target.parentNode;
// SVGTransformList of the element that has been clicked on
var tfmList = evt.target.transform.baseVal;
// Create a seperate transform object for each transform
var translate = svgroot.createSVGTransform();
translate.setTranslate(50,5);
var rotate = svgroot.createSVGTransform();
rotate.setRotate(10,0,0);
var scale = svgroot.createSVGTransform();
scale.setScale(0.8,0.8);
// apply the transformations by appending the SVGTranform objects to the SVGTransformList associated with the element
tfmList.appendItem(translate);
tfmList.appendItem(rotate);
tfmList.appendItem(scale);
}
]]> </script>
<polygon fill="orange" stroke="black" stroke-width="5"
points="100,225 100,115 130,115 70,15 70,15 10,115 40,115 40,225"
onclick="transformMe(evt)"/>
<rect x="200" y="100" width="100" height="100"
fill="yellow" stroke="black" stroke-width="5"
onclick="transformMe(evt)"/>
<text x="40" y="250"
font-family="Verdana" font-size="16" fill="green" >
Click on a shape to transform it
</text>
</svg>
Live preview:
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
SVGTransformList
|
Chrome Yes | Edge ≤18 | Firefox Yes | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android Yes | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
length
非标
|
Chrome Yes | Edge ≤79 | Firefox 9 | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android 9 | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
完整支持
兼容性未知
非标。预期跨浏览器支持较差。
SVGTransformList
SVGAElement
SVGAltGlyphElement
SVGAngle
SVGAnimateColorElement
SVGAnimateElement
SVGAnimateMotionElement
SVGAnimateTransformElement
SVGAnimatedAngle
SVGAnimatedBoolean
SVGAnimatedEnumeration
SVGAnimatedInteger
SVGAnimatedLength
SVGAnimatedLengthList
SVGAnimatedNumber
SVGAnimatedNumberList
SVGAnimatedPathData
SVGAnimatedPoints
SVGAnimatedPreserveAspectRatio
SVGAnimatedRect
SVGAnimatedString
SVGAnimatedTransformList
SVGAnimationElement
SVGCircleElement
SVGClipPathElement
SVGComponentTransferFunctionElement
SVGCursorElement
SVGDefsElement
SVGDescElement
SVGDocument
SVGElement
SVGEllipseElement
SVGFEBlendElement
SVGFEColorMatrixElement
SVGFEComponentTransferElement
SVGFECompositeElement
SVGFEConvolveMatrixElement
SVGFEDiffuseLightingElement
SVGFEDisplacementMapElement
SVGFEDistantLightElement
SVGFEDropShadowElement
SVGFEFloodElement
SVGFEFuncAElement
SVGFEFuncBElement
SVGFEFuncGElement
SVGFEFuncRElement
SVGFEGaussianBlurElement
SVGFEImageElement
SVGFEMergeElement
SVGFEMergeNodeElement
SVGFEMorphologyElement
SVGFEOffsetElement
SVGFEPointLightElement
SVGFESpecularLightingElement
SVGFESpotLightElement
SVGFETileElement
SVGFETurbulenceElement
SVGFilterElement
SVGFilterPrimitiveStandardAttributes
SVGFitToViewBox
SVGFontElement
SVGFontFaceElement
SVGFontFaceFormatElement
SVGFontFaceNameElement
SVGFontFaceSrcElement
SVGFontFaceUriElement
SVGForeignObjectElement
SVGGElement
SVGGlyphElement
SVGGradientElement
SVGGraphicsElement
SVGHKernElement
SVGImageElement
SVGLength
SVGLengthList
SVGLineElement
SVGLinearGradientElement
SVGMPathElement
SVGMarkerElement
SVGMaskElement
SVGMatrix
SVGMetadataElement
SVGMissingGlyphElement
SVGNumber
SVGNumberList
SVGPathElement
SVGPathSeg
SVGPathSegArcAbs
SVGPathSegArcRel
SVGPathSegClosePath
SVGPathSegCurvetoCubicAbs
SVGPathSegCurvetoCubicRel
SVGPathSegCurvetoCubicSmoothAbs
SVGPathSegCurvetoCubicSmoothRel
SVGPathSegCurvetoQuadraticAbs
SVGPathSegCurvetoQuadraticRel
SVGPathSegCurvetoQuadraticSmoothAbs
SVGPathSegCurvetoQuadraticSmoothRel
SVGPathSegLinetoAbs
SVGPathSegLinetoHorizontalAbs
SVGPathSegLinetoHorizontalRel
SVGPathSegLinetoRel
SVGPathSegLinetoVerticalAbs
SVGPathSegLinetoVerticalRel
SVGPathSegList
SVGPathSegMovetoAbs
SVGPathSegMovetoRel
SVGPatternElement
SVGPoint
SVGPointList
SVGPolygonElement
SVGPolylineElement
SVGPreserveAspectRatio
SVGRadialGradientElement
SVGRect
SVGRectElement
SVGSVGElement
SVGScriptElement
SVGSetElement
SVGStopElement
SVGStringList
SVGStylable
SVGStyleElement
SVGSwitchElement
SVGSymbolElement
SVGTRefElement
SVGTSpanElement
SVGTests
SVGTextContentElement
SVGTextElement
SVGTextPathElement
SVGTextPositioningElement
SVGTitleElement
SVGTransform
SVGTransformable
SVGURIReference
SVGUnitTypes
SVGUseElement
SVGVKernElement
SVGViewElement
SVGZoomAndPan
SVGZoomEvent
TimeEvent