-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvivus-svg.html
135 lines (114 loc) · 3.91 KB
/
vivus-svg.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link href="https://polygit.org/components/polymer/polymer.html" rel="import">
<link rel="import" href="https://rawgit.com/lloydud/vivus-svg/master/vivus-import.html">
<!--
A light weight wrapper around vivus-svg
Example:
<vivus-svg file="hi.svg" type="scenario-sync" start="autostart" duration="20" dash-gap="20" force-render="false"></vivus-svg>
@demo demo/index.html
@hero hero.svg
-->
<dom-module id="vivus-svg">
<template>
<style>
:host {
display: block;
box-sizing: border-box;
}
</style>
<div id="svg"></div>
</template>
<script>
Polymer({
is: 'vivus-svg',
properties: {
/** Link to the SVG to animate. If set, Vivus will create an object tag and append it to the DOM element given to the constructor. Be careful, use the onReady callback before playing with the Vivus instance. */
file: {
type: String
},
/** The fill color of the svg */
fill: {
type: String,
value: 'white'
},
/** The stroke color of the svg */
stroke: {
type: String,
value: 'black'
},
/** Defines what kind of animation will be used: delayed, async, oneByOne, script, scenario or scenario-sync. [Default: delayed] */
type: {
type: String,
value: 'delayed'
},
/** Animation duration, in frames. [Default: 200] */
duration: {
type: Number,
value: 200
},
/** Defines how to trigger the animation (inViewport once the SVG is in the viewport, manual gives you the freedom to call draw method to start, autostart makes it start right now). [Default: inViewport] **/
start: {
type: String,
value: 'inViewport'
},
/** Time between the drawing of first and last path, in frames (only for delayed animations). */
delay: {
type: Number,
value: 0
},
/** Whitespace extra margin between dashes. Increase it in case of glitches at the initial state of the animation. [Default: 2] */
dashGap: {
type: Number,
value: 2
},
/** Force the browser to re-render all updated path items. By default, the value is true on IE only. (check the 'troubleshoot' section for more details). */
forceRender: {
type: Boolean,
value: true
},
/** Removes all extra styling on the SVG, and leaves it as original. */
selfDestroy: {
type: Boolean,
value: false
},
_img: {
type: Object
}
},
animate: function () {
this._img.reset();
this._img.play();
},
ready: function () {
var that = this;
this._img = new Vivus(this.$.svg,
{
type: this.type,
duration: this.duration,
file: this.file,
start: this.start,
delay: this.delay,
dashGap: this.dashGap,
forceRender: this.forceRender,
selfDestroy: this.selfDestroy,
onReady: function (myVivus) {
/**
* @fires ready
*/
that.fire('ready', myVivus);
myVivus.el.setAttribute('fill', that.fill);
myVivus.el.setAttribute('stroke', that.stroke);
}
});
}
});
</script>
</dom-module>