導航:首頁 > 編程語言 > js讀取svg

js讀取svg

發布時間:2025-06-15 04:59:46

㈠ 如何通過js獲取HTML中iframe中的SVG整個文檔

先找到iframe對象,再通過iframe的contentDocument屬性獲取SVG整個文檔對象

<iframesrc="svg/02.svg"frameborder="0"width="500"height="300"id="f1"></iframe>
varobj=document.getElementById("f1");
vard=obj.contentDocument;

㈡ 如何用 JS 獲取 SVG 內 path 元素中的圖形的實際位置及尺寸

用 JS 獲取 SVG 內 path 元素中的圖形的實際位置及尺寸的方法:
1、使用內getElementById獲取容svg節點對象:
var el = document.getElementById("yourElement");
2、調用getBoundingClientRect獲取path的邊界矩形的位置:
var rect = el.getBoundingClientRect();
3、分別獲取width和height屬性就得到實際位置了。

console.log( rect.width );
console.log( rect.height);

㈢ svg無法載入外部js

<svgwidth="580"height="399.9999999"
xmlns="http://www.w3.org/2000/svg"version="1.2"baseProfile="tiny"
xmlns:ev="http://www.w3.org/2001/xml-events">
<scripttype="application/ecmascript"xlink:href="demo.js"/>

demo.js

//demo.js刪除<script></script>

我自己寫了一個

文件:a.svg

<svgwidth="100%"height="100%"viewBox="00100100"version="1.2"baseProfile="full"
xmlns="http://www.w3.org/2000/svg"xmlns:xlink="http://www.w3.org/2000/xlink"xmlns:ev="http://www.w3.org/2001/xml-events">
<scripttype="application/ecmascript"href="s.es"/>
<circlecx="50"cy="50"r="45"fill="green"onclick="change(evt)"/>
</svg>

文件:s.es

functionchange(evt){
if(evt.target.getAttribute('fill')==='green'){
evt.target.setAttribute('fill','red')
}else{
evt.target.setAttribute('fill','green')
}
}

㈣ JS正則截取指定svg文本

varstr='<g><path></path></g><gclass="className"><path></path></g><gclass="className"><path></path></g><g><path></path></g>';
varreg=/<g[^>]*class[="'s]+className["']?[^>]*>(?:(?!</g>)[sS])*</g>/gi;
str.match(reg);

閱讀全文

與js讀取svg相關的資料

熱點內容
壓縮文件搜索 瀏覽:540
mysql忘記密碼 瀏覽:826
內部儲存中哪些文件夾是沒有用的 瀏覽:203
蘋果手機怎麼還原所有設置 瀏覽:521
cad修復zw文件 瀏覽:150
附件存儲在資料庫中 瀏覽:71
dsp原理與應用教程思考題 瀏覽:632
cad新建和保存文件 瀏覽:449
編程怎麼打出上標乘號 瀏覽:109
在網站上賣書需要什麼 瀏覽:518
酷狗app清理緩存文件在哪 瀏覽:360
尿檢中哪個數據能判斷腎結石 瀏覽:692
平板怎麼保存網頁視頻文件 瀏覽:667
只狼應該創建哪些文件夾來 瀏覽:543
為了保證中斷服務程序 瀏覽:416
編程貓賽車得分怎麼統計 瀏覽:38
excel每次打開一個文件都彈出窗口 瀏覽:615
無人區被禁版本 瀏覽:739
掌中雲是什麼網站 瀏覽:590
電信電視超級密碼 瀏覽:567

友情鏈接