-
Notifications
You must be signed in to change notification settings - Fork 1
/
drop.js
77 lines (72 loc) · 1.92 KB
/
drop.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
72
73
74
75
76
77
/**
* @file
* Provides Hurricane default renderer "drop".
*/
(function($){
$.hurricane.drop = $.hurricane.base.extend({
setup: function(options) {
this.$dot = $('<div></div>').css({
position: 'absolute',
top: '0px',
left: '0px',
width: this.$el.width(),
height: this.$el.height()
});
this.$el.append(this.$dot);
this.stopped = true;
this.speed = 15000 / options['word-spacing'];
this.active = this.rgb2hex(options['color']);
this.inactive = this.rgb2hex(options['background-color']);
var radius = this.$dot.width() / 2;
var speed = this.speed / 1000;
var css = {
'background-color': this.inactive
};
$.each(['', '-webkit-', '-moz-', '-ms-', '-o-'], function(index, prefix){
css[prefix + 'border-radius'] = radius + 'px';
css[prefix + 'transition'] = 'background-color ' + speed + 's ease';
});
this.$dot.css(css);
},
rgb2hex: function (rgb) {
var match = rgb.match(/^rgb[a?]\((\d+),\s*(\d+),\s*(\d+)\)$/);
if (!match) {
return rgb;
}
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(match[1]) + hex(match[2]) + hex(match[3]);
},
pulseUp: function () {
if (this.stopped) {
return;
}
var that = this;
this.$dot.css({
'background-color': this.active
});
window.setTimeout(function(){
that.pulseDown();
}, this.speed);
},
pulseDown: function () {
var that = this;
this.$dot.css({
'background-color': this.inactive
});
window.setTimeout(function(){
that.pulseUp();
}, this.speed);
},
start: function () {
if (this.stopped) {
this.stopped = false;
this.pulseUp();
}
},
stop: function () {
this.stopped = true;
}
});
}(jQuery));