3 回答
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | <!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < meta http-equiv = "X-UA-Compatible" content = "IE=edge,chrome=1" > < title >Examples</ title > < meta name = "description" content = "" > < meta name = "keywords" content = "" > < link href = "" rel = "stylesheet" > < style type = "text/css" > svg{ background:#FCFCFC; display: block; margin: 20px auto; border: 1px solid #CCC; } #transform{ width: 300px; } </ style > </ head > < body > < fieldset > < legend >set</ legend > < label >group: < select id = "group" > < option value = "a" >a</ option > < option value = "b" >-b</ option > < option value = "c" >--c</ option > < option value = "d" >-d</ option > </ select > </ label > < label >change < input id = "tc" type = "text" /> < span id = "ts" ></ span > </ label > </ fieldset > < svg xmlns = "http;//www.w3.org/2000/svg" width = "1000" height = "600" viewBox = "-200.5 -100.5 1000 600" > < defs > < g id = "coord" > < line x1 = "0" y1 = "0" x2 = "300" y2 = "0" /> < line x1 = "0" y1 = "0" x2 = "0" y2 = "300" /> < circle cx = "0" cy = "0" r = "2" /> < circle cx = "100" cy = "0" r = "2" /> < circle cx = "200" cy = "0" r = "2" /> < circle cx = "0" cy = "100" r = "2" /> < circle cx = "0" cy = "200" r = "2" /> </ g > </ defs > < use xlink:href = "#coord" stroke = 'black' fill = "black" /> < text fill = "black" x = "5" y = "20" >hello,world!</ text > < g id = "a" stroke = "red" fill = "red" > < use xlink:href = "#coord" /> < text x = "5" y = "20" >a</ text > < g id = "b" stroke = "blue" fill = "blue" > < use xlink:href = "#coord" /> < text x = "5" y = "20" >b</ text > < g id = "c" stroke = "green" fill = "green" > < use xlink:href = "#coord" /> < text x = "5" y = "20" >c</ text > </ g > </ g > < g id = "d" stroke = "pink" fill = "pink" > < use xlink:href = "#coord" /> < text x = "5" y = "20" >d</ text > </ g > </ g > </ svg > < script type = "text/javascript" > function target(){ return document.getElementById(group.value); } function tc2ts(tc){ var arr = (tc || '').split(' '); var ts = ''; var elem,lastElemType; var cmd = { 't':'translate(', 'r':'rotate(', 's':'scale(', 'm':'matrix(' }; while(elem = arr.shift()){ if(cmd[elem]){ if(lastElemType == 'number') ts +=') '; ts += cmd[elem]; lastElemType = 'command'; }else{ if(lastElemType == 'number') ts += ', '; ts += elem; lastElemType = 'number'; } } if(ts.length) ts += ')'; return ts; } group.oninput = function(){ tc.value = target().tc || ''; ts.innerHTML = tc2ts(tc.value); }; tc.oninput = function(){ target().tc = tc.value; target().setAttribute('transform',ts.innerHTML = tc2ts(tc.value)); } </ script > </ body > </ html > |
举报
0/150
提交
取消