SVGTransformList: clear() 方法
SVGTransformList 介面的 clear() 方法會清除列表中的所有當前項,結果是一個空列表。
語法
js
clear()
引數
無。
返回值
無(undefined)。
異常
NoModificationAllowedErrorDOMException-
如果
SVGTransformList對應於只讀屬性,或者物件本身是隻讀的,則會丟擲此異常。
示例
清除 SVG 元素的所有變換
html
<svg width="200" height="200" id="mySvg">
<rect width="100" height="100" fill="blue" transform="translate(50,50)" />
</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;
// Apply a translate transformation to the <rect> element
const translateTransform = svgElement.createSVGTransform();
translateTransform.setTranslate(50, 50);
transformList.appendItem(translateTransform);
// Number of transformations before clearing
console.log(
`Number of transformations before clearing: ${transformList.length}`,
); // Output: 1
// Clear all transformations from the list
transformList.clear();
// Number of transformations after clearing
console.log(
`Number of transformations after clearing: ${transformList.length}`,
); // Output: 0
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGNameList__clear |
瀏覽器相容性
載入中…