-
Notifications
You must be signed in to change notification settings - Fork 2
/
snaptut-animate-text.html
71 lines (54 loc) · 1.89 KB
/
snaptut-animate-text.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
<!DOCTYPE html>
<html>
<head>
<title>Snap.svg Tutorial</title>
<script src="analytics.js"></script>
</head>
<body>
<link href="/snapstyle.css" rel="stylesheet">
<div id="container"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="snap.svg.js"></script>
<a href="http://snapsvg.io/docs/">Snap Docs</a> <a href="/">More SVG Dabbles</a> <a href="/">Contact Me</a>
<article>
<h1 class="heading">Animate </h1>
<div class="intro">Here's an example of animating text individually </div>
<pre class="codestuff"><code contenteditable="true">
var s = Snap("#svgout");
var myCharArray, textElArray, myTrans;
var offsetY = 50;
var myTextStringArray = ["Lorem ipsum dolor sit amet, consectetur adipisicing elit",
"sed do eiusmod tempor incididunt ut labor et dolore magna aliqua.",
" Ut enim ad minim veniam, quis nostrud exercitation ullamco" ];
var myGroup = s.g().attr({ fill: "red", "font-size": "20px" });
for( var a=0; a<myTextStringArray.length; a++) {
myCharArray = myTextStringArray[a].split('');
textElArray = myGroup.text(200, 120, myCharArray).attr({ opacity : 1, y: (a * 20 + offsetY) });
};
myTspans = myGroup.selectAll("tspan").attr({
opacity: 0
});
function animFunc( element ) {
Snap.animate(0,1, function( value ) {
element.attr({ opacity: value, rotate: (value * 360) });
}, 1000 );
}
for( var i=0; i < myTspans.length; i++ ) {
setTimeout(
animFunc.bind(null, myTspans[i])
, i * 100);
}
</xmp>
</code>
<button class="run">Edit/Run</button>
</pre>
</article>
<div class="intro">SVGout area...</div>
<div class="output">
<svg id="svgout" width="400" height="400"></svg>
</div>
<div class="intro">The actual svg markup looks like this (when you've clicked on run)....</div>
<div id="htmlraw"></div>
<script src="snaptut.js"></script></script>
<script src="hijs.js"></script>
</body>