-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselfw.js
More file actions
47 lines (37 loc) · 908 Bytes
/
selfw.js
File metadata and controls
47 lines (37 loc) · 908 Bytes
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
(function($){
$.fn.extend({
//pass the options variable to the function
selfw: function(options) {
var defaults = {
text: $(this).text(),
time: 100,
random: true
};
var options = $.extend(defaults, options);
var that = $(this);
function init(){
that.each(function(){
element = $(this);
element.empty();
timeout(options.text, 0, element);
});
}
function timeout(word, index, $this ){
var count = word.length -1,
time;
if(options.random === true)
time = Math.floor(Math.random() * options.time);
else
time = options.time;
console.log(time);
if(index <= count){
setTimeout(function(){
$this.append(word[index]);
timeout(word, index+1, $this);
}, time);
}
}
init(); //kick off the goodness
}
});
})(jQuery);