forked from esehara/jquery-kabuki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-kabuki.js
142 lines (120 loc) · 4.76 KB
/
jquery-kabuki.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
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
136
137
138
139
140
141
142
(function($) {
$.fn.kabuki = function() {
var _kabuki = {
_element: this,
_if_null: function(arg, defaults) {
if (typeof arg === "undefined") {
arg = defaults;
}
return arg;
},
_randint: function(options) {
options.min = this._if_null(options.min, 0);
return (Math.floor(Math.random() * options.max) + options.min);
},
_randrgb: function(options) {
var rgb_setting = this._if_null(options, {min: 0, max: 255});
return 'rgb(' + this._randint(rgb_setting) + ',' + this._randint(rgb_setting) + ',' + this._randint(rgb_setting) + ')';
},
_initialize: function(valuables, defaults) {
valuables = this._if_null(valuables, {});
var key;
for (key in defaults) {
if(defaults.hasOwnProperty(key)) {
valuables[key] = this._if_null(valuables[key], defaults[key]);
}
}
return valuables;
},
rainbow: function(options) {
var me = this;
var defaults = {
'css': 'color',
'interval': 100,
};
options = this._initialize(options, defaults);
setInterval(function() {
var _css_config = {};
_css_config[options.css] = me._randrgb(options.color);
me._element.css(_css_config);
}, options.interval);
return me;
},
earthquake: function(options) {
var me = this;
var defaults = {
'css': 'padding',
'interval': 100,
'max': 100,
'min': 0
};
options = this._initialize(options, defaults);
setInterval(function(){
var _css_config = {};
_css_config[options.css] = me._randint({max: options.max, min: options.min});
me._element.css(_css_config);
}, options.interval);
return me;
},
bound: function(options) {
var me = this;
var defaults = {
'css': 'font-size',
'interval': 50,
'max': 72,
'min': 8,
'start': 16,
'reverse': false};
options = this._initialize(options, defaults);
setInterval(function() {
var _css_config = {};
var _status = options;
if (_status.reverse) {
_status.start --;
} else {
_status.start ++;
}
if (_status.start > _status.max) {
_status.reverse = true;
}
if (_status.start < _status.min) {
_status.reverse = false;
}
_css_config[_status.css] = _status.start;
me._element.css(_css_config);
}, options.interval);
},
_background_size: function(me, options) {
var background_url = $(me._element).css('background-image');
var url = background_url.replace('url(', '').replace(')', '').replace('"', '').replace("'", "");
var image = $('<img />');
image.hide();
image.bind('load', function() {
var width = $(this).width();
me._after_infinity_scroll(me, options, width);
});
$('body').append(image);
image.attr('src', url);
},
_pre_infinity_scroll: function(options) {
var me = this;
options.speed = this._if_null(options.speed, 1);
this._background_size(me, options);
},
_after_infinity_scroll: function(me, options, width) {
var current = 0;
setInterval(function() {
current ++;
$(me._element).css("backgroundPosition", current + "px 0");
if (current > width) {
current = 0;
}
}, options.interval);
},
infinity_scroll: function(options) {
this._pre_infinity_scroll(options);
},
};
return _kabuki;
};
}(jQuery));