-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
194 lines (157 loc) · 4.44 KB
/
main.js
File metadata and controls
194 lines (157 loc) · 4.44 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//Select element function
const selectElement = function(element){
return document.querySelector(element);
};
let menuToggler = selectElement('.menu-toggle');
let body = selectElement('body');
let nav = selectElement('.nav-list');
menuToggler.addEventListener('click',function(){
body.classList.toggle('open');
});
nav.addEventListener('click',function(){
var x = screen.width;
if(x<=900)
{body.classList.toggle('open');
particles.nb = 10;}
});
window.sr=ScrollReveal();
sr.reveal('.animate-left',{
origin: 'left',
duration: 800,
distance: '25rem',
delay:400
});
sr.reveal('.animate-top',{
origin: 'top',
duration: 800,
distance: '25rem',
delay:400
});
sr.reveal('.animate-bottom',{
origin: 'bottom',
duration: 800,
distance: '25rem',
delay:400
});
/* particlesJS('dom-id', params);
/* @dom-id : set the html tag id [string, optional, default value : particles-js]
/* @params: set the params [object, optional, default values : check particles.js] */
/* config dom id (optional) + config particles params */
(function () {
'use strict';
window.addEventListener('load', function () {
var canvas = document.getElementById('canvas');
if (!canvas || !canvas.getContext) {
return false;
}
/********************
Random Number
********************/
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
/********************
Var
********************/
var ctx = canvas.getContext('2d');
var X = canvas.width = window.innerWidth;
var Y = canvas.height = window.innerHeight;
var mouseX = null;
var mouseY = null;
var shapeNum = 50;
var shapes = [];
var style = {
black: 'black',
white: 'white',
lineWidth: 4,
};
/********************
Animation
********************/
window.requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(cb) {
setTimeout(cb, 17);
};
/********************
Shape
********************/
function Shape(ctx, x, y) {
this.ctx = ctx;
this.init(x, y);
}
Shape.prototype.init = function(x, y) {
this.x = x;
this.y = y;
this.r = rand(10, 25);
this.ga = Math.random() * Math.random() * Math.random() * Math.random();
this.v = {
x: Math.random(),
y: -1
};
this.l = rand(0, 20);
this.sl = this.l;
};
Shape.prototype.updateParams = function() {
var ratio = this.l / this.sl;
//this.r *= ratio;
this.l -= 1;
if (this.l < 0) {
this.init(X * (Math.random() + Math.random()) / 2, rand(0, Y));
}
};
Shape.prototype.updatePosition = function() {
this.x += Math.random();
this.y += -Math.random();
};
Shape.prototype.draw = function() {
var ctx = this.ctx;
ctx.save();
ctx.globalCompositeOperation = 'lighter';
ctx.globalAlpha = this.ga;
//ctx.fillStyle = 'rgb(123, 252, 100)';
ctx.fillStyle = 'white';
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2, false);
ctx.fill();
ctx.restore();
};
Shape.prototype.render = function(i) {
this.updatePosition();
this.updateParams();
this.draw();
};
for (var i = 0; i < shapeNum; i++) {
var s = new Shape(ctx, X * (Math.random() + Math.random()) / 2, rand(0, Y));
shapes.push(s);
}
/********************
Render
********************/
function render() {
ctx.clearRect(0, 0, X, Y);
for (var i = 0; i < shapes.length; i++) {
shapes[i].render(i);
}
requestAnimationFrame(render);
}
render();
/********************
Event
********************/
function onResize() {
X = canvas.width = window.innerWidth;
Y = canvas.height = window.innerHeight;
}
window.addEventListener('resize', function() {
onResize();
});
window.addEventListener('mousemove', function(e) {
mouseX = e.clientX;
mouseY = e.clientY;
}, false);
});
})();