SVGTransformList:removeItem() 方法
SVGTransformList 接口的 removeItem() 方法用于从列表中移除现有项。
语法
js
removeItem(index)
参数
index-
一个
integer;要移除项的索引,为无符号长整型。
返回值
一个 SVGTransform 对象;从列表中移除的项。
异常
此方法可能会抛出以下类型之一的DOMException:
NoModificationAllowedErrorDOMException-
如果
SVGTransformList对应于只读属性,或者对象本身是只读的,则会抛出此异常。 IndexSizeErrorDOMException-
如果索引号大于或等于
numberOfItems,则会抛出此异常。
示例
从列表中移除变换
html
<svg width="200" height="200" id="mySvg">
<rect
width="100"
height="100"
fill="blue"
transform="translate(50,50) rotate(45)" />
</svg>
js
const svgElement = document.querySelector("svg");
const rectElement = svgElement.querySelector("rect");
// Access the transform list of the <rect> element
const transformList = rectElement.transform.baseVal;
const removedTransform = transformList.removeItem(0);
console.dir(removedTransform); // Output: SVGTransform { type: 2, matrix: SVGMatrix, angle: 0 }
// The updated list length
console.log(`Updated number of transformations: ${transformList.length}`); // Output: 1
规范
| 规范 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGNameList__removeItem |
浏览器兼容性
加载中…