luckyphoenix 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/js/ribbons.js CHANGED
@@ -1,334 +1,334 @@
1
- (function (name, factory) {
2
- if (typeof window === "object") {
3
- window[name] = factory()
4
- }
5
- })("Ribbons", function () {
6
- var _w = window,
7
- _b = document.body,
8
- _d = document.documentElement;
9
- var random = function () {
10
- if (arguments.length === 1) {
11
- if (Array.isArray(arguments[0])) {
12
- var index = Math.round(random(0, arguments[0].length - 1));
13
- return arguments[0][index]
14
- }
15
- return random(0, arguments[0])
16
- } else if (arguments.length === 2) {
17
- return Math.random() * (arguments[1] - arguments[0]) + arguments[0]
18
- }
19
- return 0
20
- };
21
- var screenInfo = function (e) {
22
- var width = Math.max(0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0),
23
- height = Math.max(0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0),
24
- scrollx = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0),
25
- scrolly = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0);
26
- return {
27
- width: width,
28
- height: height,
29
- ratio: width / height,
30
- centerx: width / 2,
31
- centery: height / 2,
32
- scrollx: scrollx,
33
- scrolly: scrolly
34
- }
35
- };
36
- var mouseInfo = function (e) {
37
- var screen = screenInfo(e),
38
- mousex = e ? Math.max(0, e.pageX || e.clientX || 0) : 0,
39
- mousey = e ? Math.max(0, e.pageY || e.clientY || 0) : 0;
40
- return {
41
- mousex: mousex,
42
- mousey: mousey,
43
- centerx: mousex - screen.width / 2,
44
- centery: mousey - screen.height / 2
45
- }
46
- };
47
- var Point = function (x, y) {
48
- this.x = 0;
49
- this.y = 0;
50
- this.set(x, y)
51
- };
52
- Point.prototype = {
53
- constructor: Point,
54
- set: function (x, y) {
55
- this.x = x || 0;
56
- this.y = y || 0
57
- },
58
- copy: function (point) {
59
- this.x = point.x || 0;
60
- this.y = point.y || 0;
61
- return this
62
- },
63
- multiply: function (x, y) {
64
- this.x *= x || 1;
65
- this.y *= y || 1;
66
- return this
67
- },
68
- divide: function (x, y) {
69
- this.x /= x || 1;
70
- this.y /= y || 1;
71
- return this
72
- },
73
- add: function (x, y) {
74
- this.x += x || 0;
75
- this.y += y || 0;
76
- return this
77
- },
78
- subtract: function (x, y) {
79
- this.x -= x || 0;
80
- this.y -= y || 0;
81
- return this
82
- },
83
- clampX: function (min, max) {
84
- this.x = Math.max(min, Math.min(this.x, max));
85
- return this
86
- },
87
- clampY: function (min, max) {
88
- this.y = Math.max(min, Math.min(this.y, max));
89
- return this
90
- },
91
- flipX: function () {
92
- this.x *= -1;
93
- return this
94
- },
95
- flipY: function () {
96
- this.y *= -1;
97
- return this
98
- }
99
- };
100
- var Factory = function (options) {
101
- this._canvas = null;
102
- this._context = null;
103
- this._sto = null;
104
- this._width = 0;
105
- this._height = 0;
106
- this._scroll = 0;
107
- this._ribbons = [];
108
- this._options = {
109
- colorSaturation: "80%",
110
- colorBrightness: "60%",
111
- colorAlpha: 0.65,
112
- colorCycleSpeed: 6,
113
- verticalPosition: "center",
114
- horizontalSpeed: 150,
115
- ribbonCount: 5,
116
- strokeSize: 5,
117
- parallaxAmount: -0.5,
118
- animateSections: true
119
- };
120
- this._onDraw = this._onDraw.bind(this);
121
- this._onResize = this._onResize.bind(this);
122
- this._onScroll = this._onScroll.bind(this);
123
- this.setOptions(options);
124
- this.init()
125
- };
126
- Factory.prototype = {
127
- constructor: Factory,
128
- setOptions: function (options) {
129
- if (typeof options === "object") {
130
- for (var key in options) {
131
- if (options.hasOwnProperty(key)) {
132
- this._options[key] = options[key]
133
- }
134
- }
135
- }
136
- },
137
- init: function () {
138
- try {
139
- this._canvas = document.createElement("canvas");
140
- this._canvas.style["display"] = "block";
141
- this._canvas.style["position"] = "fixed";
142
- this._canvas.style["margin"] = "0";
143
- this._canvas.style["padding"] = "0";
144
- this._canvas.style["border"] = "0";
145
- this._canvas.style["outline"] = "0";
146
- this._canvas.style["left"] = "0";
147
- this._canvas.style["top"] = "0";
148
- this._canvas.style["width"] = "100%";
149
- this._canvas.style["height"] = "100%";
150
- this._canvas.style["z-index"] = "9999";
151
- this._canvas.style["pointer-events"] = "none";
152
- this._onResize();
153
- this._context = this._canvas.getContext("2d");
154
- this._context.clearRect(0, 0, this._width, this._height);
155
- this._context.globalAlpha = this._options.colorAlpha;
156
- window.addEventListener("resize", this._onResize);
157
- window.addEventListener("scroll", this._onScroll);
158
- document.body.appendChild(this._canvas)
159
- } catch (e) {
160
- console.warn("Canvas Context Error: " + e.toString());
161
- return
162
- }
163
- this._onDraw()
164
- },
165
- addRibbon: function () {
166
- var dir = Math.round(random(1, 9)) > 5 ? "right" : "left",
167
- stop = 1000,
168
- hide = 200,
169
- min = 0 - hide,
170
- max = this._width + hide,
171
- movex = 0,
172
- movey = 0,
173
- startx = dir === "right" ? min : max,
174
- starty = Math.round(random(0, this._height));
175
- if (/^(top|min)$/i.test(this._options.verticalPosition)) {
176
- starty = 0 + hide
177
- } else if (/^(middle|center)$/i.test(this._options.verticalPosition)) {
178
- starty = this._height / 2
179
- } else if (/^(bottom|max)$/i.test(this._options.verticalPosition)) {
180
- starty = this._height - hide
181
- }
182
- var ribbon = [],
183
- point1 = new Point(startx, starty),
184
- point2 = new Point(startx, starty),
185
- point3 = null,
186
- color = Math.round(random(0, 360)),
187
- delay = 0;
188
- while (true) {
189
- if (stop <= 0) break;
190
- stop--;
191
- movex = Math.round((Math.random() * 1 - 0.2) * this._options.horizontalSpeed);
192
- movey = Math.round((Math.random() * 1 - 0.5) * (this._height * 0.25));
193
- point3 = new Point();
194
- point3.copy(point2);
195
- if (dir === "right") {
196
- point3.add(movex, movey);
197
- if (point2.x >= max) break
198
- } else if (dir === "left") {
199
- point3.subtract(movex, movey);
200
- if (point2.x <= min) break
201
- }
202
- ribbon.push({
203
- point1: new Point(point1.x, point1.y),
204
- point2: new Point(point2.x, point2.y),
205
- point3: point3,
206
- color: color,
207
- delay: delay,
208
- dir: dir,
209
- alpha: 0,
210
- phase: 0
211
- });
212
- point1.copy(point2);
213
- point2.copy(point3);
214
- delay += 4;
215
- color += this._options.colorCycleSpeed
216
- }
217
- this._ribbons.push(ribbon)
218
- },
219
- _drawRibbonSection: function (section) {
220
- if (section) {
221
- if (section.phase >= 1 && section.alpha <= 0) {
222
- return true
223
- }
224
- if (section.delay <= 0) {
225
- section.phase += 0.02;
226
- section.alpha = Math.sin(section.phase) * 1;
227
- section.alpha = section.alpha <= 0 ? 0 : section.alpha;
228
- section.alpha = section.alpha >= 1 ? 1 : section.alpha;
229
- if (this._options.animateSections) {
230
- var mod = Math.sin(1 + section.phase * Math.PI / 2) * 0.1;
231
- if (section.dir === "right") {
232
- section.point1.add(mod, 0);
233
- section.point2.add(mod, 0);
234
- section.point3.add(mod, 0)
235
- } else {
236
- section.point1.subtract(mod, 0);
237
- section.point2.subtract(mod, 0);
238
- section.point3.subtract(mod, 0)
239
- }
240
- section.point1.add(0, mod);
241
- section.point2.add(0, mod);
242
- section.point3.add(0, mod)
243
- }
244
- } else {
245
- section.delay -= 0.5
246
- }
247
- var s = this._options.colorSaturation,
248
- l = this._options.colorBrightness,
249
- c = "hsla(" + section.color + ", " + s + ", " + l + ", " + section.alpha + " )";
250
- this._context.save();
251
- if (this._options.parallaxAmount !== 0) {
252
- this._context.translate(0, this._scroll * this._options.parallaxAmount)
253
- }
254
- this._context.beginPath();
255
- this._context.moveTo(section.point1.x, section.point1.y);
256
- this._context.lineTo(section.point2.x, section.point2.y);
257
- this._context.lineTo(section.point3.x, section.point3.y);
258
- this._context.fillStyle = c;
259
- this._context.fill();
260
- if (this._options.strokeSize > 0) {
261
- this._context.lineWidth = this._options.strokeSize;
262
- this._context.strokeStyle = c;
263
- this._context.lineCap = "round";
264
- this._context.stroke()
265
- }
266
- this._context.restore()
267
- }
268
- return false
269
- },
270
- _onDraw: function () {
271
- for (var i = 0, t = this._ribbons.length; i < t; ++i) {
272
- if (!this._ribbons[i]) {
273
- this._ribbons.splice(i, 1)
274
- }
275
- }
276
- this._context.clearRect(0, 0, this._width, this._height);
277
- for (var a = 0; a < this._ribbons.length; ++a) {
278
- var ribbon = this._ribbons[a],
279
- numSections = ribbon.length,
280
- numDone = 0;
281
- for (var b = 0; b < numSections; ++b) {
282
- if (this._drawRibbonSection(ribbon[b])) {
283
- numDone++
284
- }
285
- }
286
- if (numDone >= numSections) {
287
- this._ribbons[a] = null
288
- }
289
- }
290
- if (this._ribbons.length < this._options.ribbonCount) {
291
- this.addRibbon()
292
- }
293
- requestAnimationFrame(this._onDraw)
294
- },
295
- _onResize: function (e) {
296
- var screen = screenInfo(e);
297
- this._width = screen.width;
298
- this._height = screen.height;
299
- if (this._canvas) {
300
- this._canvas.width = this._width;
301
- this._canvas.height = this._height;
302
- if (this._context) {
303
- this._context.globalAlpha = this._options.colorAlpha
304
- }
305
- }
306
- },
307
- _onScroll: function (e) {
308
- var screen = screenInfo(e);
309
- this._scroll = screen.scrolly
310
- }
311
- };
312
- return Factory
313
- });
314
-
315
- var ribbonDom = document.getElementById('ribbon');
316
- var mobile = ribbonDom.getAttribute("mobile");
317
-
318
- if (mobile == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) {
319
-
320
- } else {
321
- new Ribbons({
322
- colorSaturation: "60%",
323
- colorBrightness: "50%",
324
- colorAlpha: 0.3,
325
- colorCycleSpeed: 8,
326
- verticalPosition: "random",
327
- horizontalSpeed: 200,
328
- ribbonCount: 2,
329
- strokeSize: 0,
330
- parallaxAmount: -0.2,
331
- animateSections: true
332
- });
333
- }
334
-
1
+ (function (name, factory) {
2
+ if (typeof window === "object") {
3
+ window[name] = factory()
4
+ }
5
+ })("Ribbons", function () {
6
+ var _w = window,
7
+ _b = document.body,
8
+ _d = document.documentElement;
9
+ var random = function () {
10
+ if (arguments.length === 1) {
11
+ if (Array.isArray(arguments[0])) {
12
+ var index = Math.round(random(0, arguments[0].length - 1));
13
+ return arguments[0][index]
14
+ }
15
+ return random(0, arguments[0])
16
+ } else if (arguments.length === 2) {
17
+ return Math.random() * (arguments[1] - arguments[0]) + arguments[0]
18
+ }
19
+ return 0
20
+ };
21
+ var screenInfo = function (e) {
22
+ var width = Math.max(0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0),
23
+ height = Math.max(0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0),
24
+ scrollx = Math.max(0, _w.pageXOffset || _d.scrollLeft || _b.scrollLeft || 0) - (_d.clientLeft || 0),
25
+ scrolly = Math.max(0, _w.pageYOffset || _d.scrollTop || _b.scrollTop || 0) - (_d.clientTop || 0);
26
+ return {
27
+ width: width,
28
+ height: height,
29
+ ratio: width / height,
30
+ centerx: width / 2,
31
+ centery: height / 2,
32
+ scrollx: scrollx,
33
+ scrolly: scrolly
34
+ }
35
+ };
36
+ var mouseInfo = function (e) {
37
+ var screen = screenInfo(e),
38
+ mousex = e ? Math.max(0, e.pageX || e.clientX || 0) : 0,
39
+ mousey = e ? Math.max(0, e.pageY || e.clientY || 0) : 0;
40
+ return {
41
+ mousex: mousex,
42
+ mousey: mousey,
43
+ centerx: mousex - screen.width / 2,
44
+ centery: mousey - screen.height / 2
45
+ }
46
+ };
47
+ var Point = function (x, y) {
48
+ this.x = 0;
49
+ this.y = 0;
50
+ this.set(x, y)
51
+ };
52
+ Point.prototype = {
53
+ constructor: Point,
54
+ set: function (x, y) {
55
+ this.x = x || 0;
56
+ this.y = y || 0
57
+ },
58
+ copy: function (point) {
59
+ this.x = point.x || 0;
60
+ this.y = point.y || 0;
61
+ return this
62
+ },
63
+ multiply: function (x, y) {
64
+ this.x *= x || 1;
65
+ this.y *= y || 1;
66
+ return this
67
+ },
68
+ divide: function (x, y) {
69
+ this.x /= x || 1;
70
+ this.y /= y || 1;
71
+ return this
72
+ },
73
+ add: function (x, y) {
74
+ this.x += x || 0;
75
+ this.y += y || 0;
76
+ return this
77
+ },
78
+ subtract: function (x, y) {
79
+ this.x -= x || 0;
80
+ this.y -= y || 0;
81
+ return this
82
+ },
83
+ clampX: function (min, max) {
84
+ this.x = Math.max(min, Math.min(this.x, max));
85
+ return this
86
+ },
87
+ clampY: function (min, max) {
88
+ this.y = Math.max(min, Math.min(this.y, max));
89
+ return this
90
+ },
91
+ flipX: function () {
92
+ this.x *= -1;
93
+ return this
94
+ },
95
+ flipY: function () {
96
+ this.y *= -1;
97
+ return this
98
+ }
99
+ };
100
+ var Factory = function (options) {
101
+ this._canvas = null;
102
+ this._context = null;
103
+ this._sto = null;
104
+ this._width = 0;
105
+ this._height = 0;
106
+ this._scroll = 0;
107
+ this._ribbons = [];
108
+ this._options = {
109
+ colorSaturation: "80%",
110
+ colorBrightness: "60%",
111
+ colorAlpha: 0.65,
112
+ colorCycleSpeed: 6,
113
+ verticalPosition: "center",
114
+ horizontalSpeed: 150,
115
+ ribbonCount: 5,
116
+ strokeSize: 5,
117
+ parallaxAmount: -0.5,
118
+ animateSections: true
119
+ };
120
+ this._onDraw = this._onDraw.bind(this);
121
+ this._onResize = this._onResize.bind(this);
122
+ this._onScroll = this._onScroll.bind(this);
123
+ this.setOptions(options);
124
+ this.init()
125
+ };
126
+ Factory.prototype = {
127
+ constructor: Factory,
128
+ setOptions: function (options) {
129
+ if (typeof options === "object") {
130
+ for (var key in options) {
131
+ if (options.hasOwnProperty(key)) {
132
+ this._options[key] = options[key]
133
+ }
134
+ }
135
+ }
136
+ },
137
+ init: function () {
138
+ try {
139
+ this._canvas = document.createElement("canvas");
140
+ this._canvas.style["display"] = "block";
141
+ this._canvas.style["position"] = "fixed";
142
+ this._canvas.style["margin"] = "0";
143
+ this._canvas.style["padding"] = "0";
144
+ this._canvas.style["border"] = "0";
145
+ this._canvas.style["outline"] = "0";
146
+ this._canvas.style["left"] = "0";
147
+ this._canvas.style["top"] = "0";
148
+ this._canvas.style["width"] = "100%";
149
+ this._canvas.style["height"] = "100%";
150
+ this._canvas.style["z-index"] = "9999";
151
+ this._canvas.style["pointer-events"] = "none";
152
+ this._onResize();
153
+ this._context = this._canvas.getContext("2d");
154
+ this._context.clearRect(0, 0, this._width, this._height);
155
+ this._context.globalAlpha = this._options.colorAlpha;
156
+ window.addEventListener("resize", this._onResize);
157
+ window.addEventListener("scroll", this._onScroll);
158
+ document.body.appendChild(this._canvas)
159
+ } catch (e) {
160
+ console.warn("Canvas Context Error: " + e.toString());
161
+ return
162
+ }
163
+ this._onDraw()
164
+ },
165
+ addRibbon: function () {
166
+ var dir = Math.round(random(1, 9)) > 5 ? "right" : "left",
167
+ stop = 1000,
168
+ hide = 200,
169
+ min = 0 - hide,
170
+ max = this._width + hide,
171
+ movex = 0,
172
+ movey = 0,
173
+ startx = dir === "right" ? min : max,
174
+ starty = Math.round(random(0, this._height));
175
+ if (/^(top|min)$/i.test(this._options.verticalPosition)) {
176
+ starty = 0 + hide
177
+ } else if (/^(middle|center)$/i.test(this._options.verticalPosition)) {
178
+ starty = this._height / 2
179
+ } else if (/^(bottom|max)$/i.test(this._options.verticalPosition)) {
180
+ starty = this._height - hide
181
+ }
182
+ var ribbon = [],
183
+ point1 = new Point(startx, starty),
184
+ point2 = new Point(startx, starty),
185
+ point3 = null,
186
+ color = Math.round(random(0, 360)),
187
+ delay = 0;
188
+ while (true) {
189
+ if (stop <= 0) break;
190
+ stop--;
191
+ movex = Math.round((Math.random() * 1 - 0.2) * this._options.horizontalSpeed);
192
+ movey = Math.round((Math.random() * 1 - 0.5) * (this._height * 0.25));
193
+ point3 = new Point();
194
+ point3.copy(point2);
195
+ if (dir === "right") {
196
+ point3.add(movex, movey);
197
+ if (point2.x >= max) break
198
+ } else if (dir === "left") {
199
+ point3.subtract(movex, movey);
200
+ if (point2.x <= min) break
201
+ }
202
+ ribbon.push({
203
+ point1: new Point(point1.x, point1.y),
204
+ point2: new Point(point2.x, point2.y),
205
+ point3: point3,
206
+ color: color,
207
+ delay: delay,
208
+ dir: dir,
209
+ alpha: 0,
210
+ phase: 0
211
+ });
212
+ point1.copy(point2);
213
+ point2.copy(point3);
214
+ delay += 4;
215
+ color += this._options.colorCycleSpeed
216
+ }
217
+ this._ribbons.push(ribbon)
218
+ },
219
+ _drawRibbonSection: function (section) {
220
+ if (section) {
221
+ if (section.phase >= 1 && section.alpha <= 0) {
222
+ return true
223
+ }
224
+ if (section.delay <= 0) {
225
+ section.phase += 0.02;
226
+ section.alpha = Math.sin(section.phase) * 1;
227
+ section.alpha = section.alpha <= 0 ? 0 : section.alpha;
228
+ section.alpha = section.alpha >= 1 ? 1 : section.alpha;
229
+ if (this._options.animateSections) {
230
+ var mod = Math.sin(1 + section.phase * Math.PI / 2) * 0.1;
231
+ if (section.dir === "right") {
232
+ section.point1.add(mod, 0);
233
+ section.point2.add(mod, 0);
234
+ section.point3.add(mod, 0)
235
+ } else {
236
+ section.point1.subtract(mod, 0);
237
+ section.point2.subtract(mod, 0);
238
+ section.point3.subtract(mod, 0)
239
+ }
240
+ section.point1.add(0, mod);
241
+ section.point2.add(0, mod);
242
+ section.point3.add(0, mod)
243
+ }
244
+ } else {
245
+ section.delay -= 0.5
246
+ }
247
+ var s = this._options.colorSaturation,
248
+ l = this._options.colorBrightness,
249
+ c = "hsla(" + section.color + ", " + s + ", " + l + ", " + section.alpha + " )";
250
+ this._context.save();
251
+ if (this._options.parallaxAmount !== 0) {
252
+ this._context.translate(0, this._scroll * this._options.parallaxAmount)
253
+ }
254
+ this._context.beginPath();
255
+ this._context.moveTo(section.point1.x, section.point1.y);
256
+ this._context.lineTo(section.point2.x, section.point2.y);
257
+ this._context.lineTo(section.point3.x, section.point3.y);
258
+ this._context.fillStyle = c;
259
+ this._context.fill();
260
+ if (this._options.strokeSize > 0) {
261
+ this._context.lineWidth = this._options.strokeSize;
262
+ this._context.strokeStyle = c;
263
+ this._context.lineCap = "round";
264
+ this._context.stroke()
265
+ }
266
+ this._context.restore()
267
+ }
268
+ return false
269
+ },
270
+ _onDraw: function () {
271
+ for (var i = 0, t = this._ribbons.length; i < t; ++i) {
272
+ if (!this._ribbons[i]) {
273
+ this._ribbons.splice(i, 1)
274
+ }
275
+ }
276
+ this._context.clearRect(0, 0, this._width, this._height);
277
+ for (var a = 0; a < this._ribbons.length; ++a) {
278
+ var ribbon = this._ribbons[a],
279
+ numSections = ribbon.length,
280
+ numDone = 0;
281
+ for (var b = 0; b < numSections; ++b) {
282
+ if (this._drawRibbonSection(ribbon[b])) {
283
+ numDone++
284
+ }
285
+ }
286
+ if (numDone >= numSections) {
287
+ this._ribbons[a] = null
288
+ }
289
+ }
290
+ if (this._ribbons.length < this._options.ribbonCount) {
291
+ this.addRibbon()
292
+ }
293
+ requestAnimationFrame(this._onDraw)
294
+ },
295
+ _onResize: function (e) {
296
+ var screen = screenInfo(e);
297
+ this._width = screen.width;
298
+ this._height = screen.height;
299
+ if (this._canvas) {
300
+ this._canvas.width = this._width;
301
+ this._canvas.height = this._height;
302
+ if (this._context) {
303
+ this._context.globalAlpha = this._options.colorAlpha
304
+ }
305
+ }
306
+ },
307
+ _onScroll: function (e) {
308
+ var screen = screenInfo(e);
309
+ this._scroll = screen.scrolly
310
+ }
311
+ };
312
+ return Factory
313
+ });
314
+
315
+ var ribbonDom = document.getElementById('ribbon');
316
+ var mobile = ribbonDom.getAttribute("mobile");
317
+
318
+ if (mobile == 'false' && (/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent))) {
319
+
320
+ } else {
321
+ new Ribbons({
322
+ colorSaturation: "60%",
323
+ colorBrightness: "50%",
324
+ colorAlpha: 0.3,
325
+ colorCycleSpeed: 8,
326
+ verticalPosition: "random",
327
+ horizontalSpeed: 200,
328
+ ribbonCount: 2,
329
+ strokeSize: 0,
330
+ parallaxAmount: -0.2,
331
+ animateSections: true
332
+ });
333
+ }
334
+