-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletteranimation.js
71 lines (68 loc) · 2.43 KB
/
letteranimation.js
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
/**
* letteranimation.js
* Current Version: 1.0.3
* https://www.cssanimatio.io
* Created and maintained by: Pavel
* Find me at: https://www.linkedin.com/in/yesiamrocks/
* Email: [email protected]
* Github: https://github.com/yesiamrocks/cssanimation.io
* Title: A CSS Animation Library for Developers and Ninjas
* Copyright (c) 2017 Pavel
* License: cssanimation.io is licensed under the MIT license
**/
window.onload = function() {
animateSequence();
animateRandom();
};
function animateSequence() {
var a = document.getElementsByClassName('sequence');
for (var i = 0; i < a.length; i++) {
var $this = a[i];
var letter = $this.innerHTML;
letter = letter.trim();
var str = '';
var delay = 100;
for (l = 0; l < letter.length; l++) {
if (letter[l] != ' ') {
str += '<span style="animation-delay:' + delay + 'ms; -moz-animation-delay:' + delay + 'ms; -webkit-animation-delay:' + delay + 'ms; ">' + letter[l] + '</span>';
delay += 150;
} else
str += letter[l];
}
$this.innerHTML = str;
}
}
function animateRandom() {
var a = document.getElementsByClassName('random');
for (var i = 0; i < a.length; i++) {
var $this = a[i];
var letter = $this.innerHTML;
letter = letter.trim();
var delay = 70;
var delayArray = new Array;
var randLetter = new Array;
for (j = 0; j < letter.length; j++) {
while (1) {
var random = getRandomInt(0, (letter.length - 1));
if (delayArray.indexOf(random) == -1)
break;
}
delayArray[j] = random;
}
for (l = 0; l < delayArray.length; l++) {
var str = '';
var index = delayArray[l];
if (letter[index] != ' ') {
str = '<span style="animation-delay:' + delay + 'ms; -moz-animation-delay:' + delay + 'ms; -webkit-animation-delay:' + delay + 'ms; ">' + letter[index] + '</span>';
randLetter[index] = str;
} else
randLetter[index] = letter[index];
delay += 80;
}
randLetter = randLetter.join("");
$this.innerHTML = randLetter;
}
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}