每天一個JavaScript執行個體-從js指令碼中訪問object元素中的SVG,objectsvg

來源:互聯網
上載者:User

每天一個JavaScript執行個體-從js指令碼中訪問object元素中的SVG,objectsvg

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>每天一個JavaScript執行個體-從js指令碼中訪問object元素中的SVG</title><style></style></head><body><object id="object" data = "每天一個JavaScript執行個體-SVG中的javaScript展示.svg" style="padding:20px;width:600px;height:600px;"><p>No SVG support</p></object><script type="text/javascript">var object = document.getElementById("object");object.onload = function(){var svgdoc;try {svgdoc = object.contentDocument;}catch(e){try{svgdoc = object.getSVGDocument();}catch(e){alert("SVG in object not support in your environment");}}if(!svgdoc) return;var r = svgdoc.rootElement;var square = svgdoc.getElementById("square");square.onclick = function(){var width = parseFloat(square.getAttributeNS(null,"width"));width -= 50;square.setAttributeNS(null,"width",width);var color = square.getAttributeNS(null,"fill");if(color == "bule"){square.setAttributeNS(null,"fill","yellow");square.setAttributeNS(null,"stroke","green");}else{square.setAttributeNS(null,"fill","bule");square.setAttributeNS(null,"stroke","red");}}}</script></body></html>


怎通過JS擷取HTML中iframe中的SVG整個文檔?

document.frames.iframe的name.document.....得到iframe的document對象
 
javascript 動態添加svg元素問題

給你點建議吧, 畫圖和載入是兩個步驟,
1。映像可以儲存為xml格式, svg格式, 或者存在資料庫中都可以,可以通過js把其轉換成為對象, 例如xml可以通過dom對其進行操作.最方便的還是json格式的資料, 直接轉為對象
2。畫圖, 可以把畫點, 線 形狀封裝成不同的函數, 通過和頁面事件關聯, 來操作, 可以參考JsxGraph
3. HTML5 圖形功能很強大
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.