-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
101 lines (97 loc) · 3.2 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
93
94
95
96
97
98
99
100
101
<html>
<head>
<style>
button {
background: #166bff;
border-radius: 5px;
border: none;
color: #fff;
cursor: pointer;
font-size: 16px;
font-weight: 300;
padding: 8px 8px;
}
button:hover {
background: #2a93ff;
}
.container {
align-items: center;
display: flex;
justify-content: space-evenly;
margin: 3em 0;
}
.container object {
border-radius: 8px;
width: 55%;
}
.container .inner {
background-color: #ddf5ff;
border-radius: 8px;
padding: 5px 20px;
}
.container p {
text-align: center;
}
.container code pre {
background: #1a2232;
border-radius: 8px;
color: #e5eff5;
padding: 10px;
}
</style>
<script>
function toggleAnimation() {
const svgatorObject = document.getElementById("animated-svg");
const svgatorDocument = svgatorObject.contentDocument || svgatorObject.contentWindow.document;
const svgatorElement = svgatorDocument.getElementById('ekg4JmMfD2O1');
svgatorElement?.svgatorPlayer?.ready(player => player.toggle());
}
function playAnimation() {
const svgatorObject = document.getElementById("animated-svg2");
const svgatorDocument = svgatorObject.contentDocument || svgatorObject.contentWindow.document;
const svgatorElement = svgatorDocument.getElementById('e6flsqoxhzzs1');
svgatorElement.dispatchEvent(new Event("click"));
}
</script>
</head>
<body>
<div class="container">
<object id="animated-svg" type="image/svg+xml" data="./sample-project.svg"></object>
<div class="inner">
<p>Using SVGator Player JS API, having the animation fully controlled from JS:</p>
<code>
<pre>
function toggleAnimation() {
const svgatorObject = document.getElementById("animated-svg");
const svgatorDocument = svgatorObject.contentDocument;
const svgatorElement = svgatorDocument.getElementById('ekg4JmMfD2O1');
svgatorElement?.svgatorPlayer?.ready(player => player.toggle());
}
</pre>
</code>
<p>
<button onclick="toggleAnimation()" type="button">Toggle Animation</button>
</p>
</div>
</div>
<div class="container">
<object id="animated-svg2" type="image/svg+xml" data="./logo.svg"></object>
<div class="inner">
<p>Using old method, having the animation starting on click and triggering a click event.</p>
<code>
<pre>
function playAnimation() {
const svgatorObject = document.getElementById("animated-svg");
const svgatorDocument = svgatorObject.contentDocument;
const svgatorElement = svgatorDocument.getElementById('e6flsqoxhzzs1');
svgatorElement.dispatchEvent(new Event("click"));
}
</pre>
</code>
<p>
<button onclick="playAnimation()" type="button">Start Animation</button>
</p>
</div>
</div>
</body>
</html>