close
SVG是一種以XML定義二維向量圖現的圖形格式,由W3C制定,是一個開啟的標準。
例如有一個001.svg的圖片如下:
Image002

以記事本開啟001.svg,可以發現是以一般文字來定義圖形。


xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="252.80942"
height="100.89236"
id="svg2">
id="defs4" />
id="metadata7">

rdf:about="">
image/svg+xml
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />




transform="translate(-105.26811,-111.91601)"
id="layer1">
width="251.91707"
height="100"
rx="5.5981574"
ry="50"
x="105.71429"
y="112.36218"
id="rect2985"
style="fill:#008000;stroke:#000000;stroke-width:0.89235312;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
x="151.42857"
y="178.07648"
id="text2987"
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"> x="151.42857"
y="178.07648"
id="tspan2989">文字測試



SVG可以像一般的圖片以的Tag或直接內嵌到HTML5來呈現,例如下列測試的網頁TEST01.html:



TEST SVG





xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="252.80942"
height="100.89236"
id="svg2">
id="defs4" />
id="metadata7">

rdf:about="">
image/svg+xml
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />




transform="translate(-105.26811,-111.91601)"
id="layer1">
width="251.91707"
height="100"
rx="5.5981574"
ry="50"
x="105.71429"
y="112.36218"
id="rect2985"
style="fill:#008000;stroke:#000000;stroke-width:0.89235312;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
x="151.42857"
y="178.07648"
id="text2987"
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"> x="151.42857"
y="178.07648"
id="tspan2989">文字測試





結果如下圖,可以發現兩張一模一樣的圖片在測試網頁上。
Image003

因此我試著以jQuery來動態更改SVG上的文字,程式碼如下:








Hello World





xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="252.80942"
height="100.89236"
id="svg2">




image/svg+xml
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />




transform="translate(-105.26811,-111.91601)"
id="layer1">
width="251.91707"
height="100"
rx="5.5981574"
ry="50"
x="105.71429"
y="112.36218"
id="rect2985"
style="fill:#008000;stroke:#000000;stroke-width:0.89235312;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
x="151.42857"
y="178.07648"
id="text2987"
xml:space="preserve"
style="font-size:40px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans">
x="151.42857"
y="178.07648"
id="tspan2989">文字測試









Image006
arrow
arrow
    全站熱搜

    keven 發表在 痞客邦 留言(0) 人氣()