-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.html
92 lines (87 loc) · 2.9 KB
/
index.html
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
<html>
<body>
<div class="drawarea">
<div id="draw" class="box"></div>
<div id="anim" class="box"></div>
</div>
<button id="clear">Clear</button>
<button id="download">Download svg</button>
<button id="start">Start animation</button>
<button id="stop">Stop animation</button>
<button id="downloadAnim">Donwload animation svg</button>
<style>
.drawarea {
display: flex;
flex-wrap: wrap;
}
.box {
border: 1px solid #ddd;
width: 45vw;
height: 45vw;
margin: auto;
}
</style>
<div id="anim"></div>
<script src="https://unpkg.com/@svg-drawing/[email protected]/lib/index.umd.js"></script>
<script src="https://unpkg.com/@svg-drawing/[email protected]/lib/index.umd.js"></script>
<script>
const { SvgDrawing } = SVGDCore
const { SvgAnimation } = SVGDAnimation
// Render Drawing area
// Drawing area will be resized to fit the rendering area
const drawEl = document.getElementById('draw')
const draw = new SvgDrawing(drawEl)
const clear = document.getElementById('clear')
clear.onclick = () => draw.clear()
const download = document.getElementById('download')
download.onclick = () => draw.download()
// Render Animation Area
// It is resized to fit the rendering area as well as the SvgDrawing area.
const animEl = document.getElementById('anim')
const anim = new SvgAnimation(animEl)
const start = document.getElementById('start')
start.onclick = () => {
// Sets the animation callback function
anim.setAnimation(
// Example drawing animation.
// Since the Path Object before animation is passed as an argument, it is converted and returned.
(paths, fid) => {
let len = fid
const update = []
for (let i = 0; i < paths.length; i += 1) {
if (len < paths[i].commands.length) {
paths[i].commands = paths[i].commands.slice(0, len)
update.push(paths[i])
break
}
len -= paths[i].commands.length
update.push(paths[i])
}
return update
},
// setAnimation options. `repeatCount` is related to downloadAnimation methods.
{
repeatCount: 1,
ms: 20,
}
)
// Copy drawwing data
anim.copy(draw)
// Start animation
anim.start()
}
const stop = document.getElementById('stop')
stop.onclick = () => {
// Stop Animation
anim.stop()
// Restore svg before animation.
anim.restore()
}
const da = document.getElementById('downloadAnim')
da.onclick = () => {
// Download svg with animate element.
anim.downloadAnimation()
}
</script>
</body>
</html>