[英]Get position of svg element
為什么我無法獲得cx和cy的值? 它打印一些數組。 我只需要2個值
<!DOCTYPE html> <html> <body> <svg xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="50" fill="red" id="cir"/> </svg> <script> console.log(document.getElementById("cir").cx); console.log(document.getElementById("cir").cy); </script> </body> </html>
cx
和cy
屬性是SVGAnimatedLength
對象,而不是字符串或數字。
要獲取cx
的實際值,您需要執行以下操作:
cx.baseVal.value
<!DOCTYPE html> <html> <body> <svg xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="50" fill="red" id="cir"/> </svg> <script> console.log(document.getElementById("cir").cx.baseVal.value); console.log(document.getElementById("cir").cy.baseVal.value); </script> </body> </html>
使用console.log()
而不是Console.log()
console
是由瀏覽器定義的, Console
不是(與大多數語言一樣,JS區分大小寫)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.