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 |
瀏覽器相容性
載入中…