課程
/前端開發(fā)
/Html5
/走進(jìn)SVG
代碼編寫的視頻還被快進(jìn) 以至于思路跟不上 是不是這樣會(huì)很酷??
2014-11-17
源自:走進(jìn)SVG 5-5
正在回答
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title>Document</title> </head> <body> <form?action=""> <label>Path:</label> <select?id="select"> <option?value="none">none</option> <option?value="#path1">path1</option> <option?value="#path2">path2</option> <option?value="#path3">path3</option> </select> </form> <svg?xmlns="http://www.w3.org/2000/svg"?width="800"?height="600"> <path?id="path1"?d="M?100?200?Q?200?100?300?200?T?500?200"?stroke="rgb(0,255,0)"?fill="none"/> <path?id="path2"?d="M?100?300?l?100-50?200?100?100?-50"?stroke="rgb(255,0,0)"?fill="none"?/> <path?id="path3"?d="M100?400?A?400?300?0?0?0?500?400"?stroke="blue"?fill="none"/> <text?id="text"?x="100"?y="100"?style="font-size:20px;"> Text?path?scripting.<tspan?id="tspan">動(dòng)態(tài)使用路徑文本</tspan> </text> </svg> <script> var?SVG_NS?=?'http://www.w3.org/2000/svg'; var?XLINK_NS?=?'http://www.w3.org/1999/xlink'; var?text?=?document.getElementById('text'); var?select?=?document.getElementById('select'); var?tspan?=?document.getElementById('tspan'); function?addTextPath(){ var?textPath?=?document.createElementNS(SVG_NS,'textPath'); while(text.firstChild){ textPath.appendChild(text.firstChild); } text.appendChild(textPath); } function?setTextPath(path){ var?textPath?=?text.firstChild; textPath.setAttributeNS(XLINK_NS,'xlink:href',path); var?pathElement?=?document.querySelector(path); tspan.setAttribute('fill',pathElement.getAttribute('stroke')); } function?removeTextPath(){ var?textPath?=?text.firstChild; while(textPath.firstChild){ text.appendChild(textPath.firstChild); } text.removeChild(textPath); tspan.removeAttribute('fill'); } select.addEventListener('input',function(){ var?value?=?select.value; if(text.firstChild.tagName&&text.firstChild.tagName.toLowerCase()=='textpath'){ if(value=='none')?{ removeTextPath(); }else{ removeTextPath(); addTextPath(); setTextPath(value); } }else{ if(value!='none'){ addTextPath(); setTextPath(value); } } }); </script> </body> </html>
洪爐百煉生 提問者
zdddrszj
視頻重復(fù)看一下,代碼自己打一下就可以了
weibo_等再遇見_0
舉報(bào)
SVG是HTML5 中矢量圖的標(biāo)記語言,學(xué)習(xí)后掌握更多的干貨
3 回答這課程有源代碼的下載么?
1 回答求老師上課demo的源代碼
1 回答還是希望老師能把這部分源代碼釋放出來
2 回答沒有代碼嗎 最后慕課網(wǎng)文字的那個(gè)
3 回答怎么下載課程代碼
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2014-12-15
2014-12-15
視頻重復(fù)看一下,代碼自己打一下就可以了