The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Moving Particles</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="vertical-centered-container" id="particles-background"></div>
<div class="vertical-centered-container" id="particles-foreground"></div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
* {
margin: 0;
padding: 0;
transition: all 0.25s;
}
body {
height: 100vh;
width: 100%;
overflow: hidden;
}
.vertical-centered-container {
position: absolute;
height: 100%;
width: 100%;
}
.vertical-centered-container::after {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -4px;
}
#particles-background, #particles-foreground {
top: -51%;
left: -51%;
height: 202%;
width: 202%;
transform: scale3d(0.5, 0.5, 1);
}
#particles-background {
background: radial-gradient(#003153, #002147);
}
Below is the javascript code for this video.
index.js
! function (t, e) {
"use strict";
function i(i, s) {
function o() { d.width = i.offsetWidth, d.height = i.offsetHeight, h.fillStyle = s.dotColor, h.strokeStyle = s.lineColor, h.lineWidth = s.lineWidth }
function r() {
if (u) {
f = t.innerWidth, c = t.innerHeight, h.clearRect(0, 0, d.width, d.height);
for (var e = 0; e < y.length; e++) y[e].updatePosition();
for (e = 0; e < y.length; e++) y[e].draw();
M || requestAnimationFrame(r)
}
}
function p() {
switch (this.stackPos, this.active = !0, this.layer = Math.ceil(3 * Math.random()),
this.parallaxOffsetX = 0, this.parallaxOffsetY = 0,
this.position = { x: Math.ceil(Math.random() * d.width), y: Math.ceil(Math.random() * d.height) },
this.speed = {}, s.directionX) {
case "left": this.speed.x = +(-s.maxSpeedX + Math.random() * s.maxSpeedX - s.minSpeedX).toFixed(2); break;
case "right": this.speed.x = +(Math.random() * s.maxSpeedX + s.minSpeedX).toFixed(2); break;
default: this.speed.x = +(-s.maxSpeedX / 2 + Math.random() * s.maxSpeedX).toFixed(2),
this.speed.x += this.speed.x > 0 ? s.minSpeedX : -s.minSpeedX
}
switch (s.directionY) {
case "up": this.speed.y = +(-s.maxSpeedY + Math.random() * s.maxSpeedY - s.minSpeedY).toFixed(2); break;
case "down": this.speed.y = +(Math.random() * s.maxSpeedY + s.minSpeedY).toFixed(2); break;
default: this.speed.y = +(-s.maxSpeedY / 2 + Math.random() * s.maxSpeedY).toFixed(2),
this.speed.x += this.speed.y > 0 ? s.minSpeedY : -s.minSpeedY
}
}
function l(t) { void 0 !== s[t] && s[t].call(i) }
var d, h, f, c, x, m, u = !!e.createElement("canvas").getContext, y = [], g = 0, w = 0, S = !!t.DeviceOrientationEvent,
X = 0, Y = 0, M = !1;
return s = function (t) {
t = t || {};
for (var e = 1; e < arguments.length; e++) {
var i = arguments[e];
if (i) for (var a in i) i.hasOwnProperty(a) && ("object" == typeof i[a] ? deepExtend(t[a], i[a]) : t[a] = i[a])
}
return t
}({}, t[a].defaults, s), p.prototype.draw = function () {
h.beginPath(),
h.arc(this.position.x + this.parallaxOffsetX, this.position.y + this.parallaxOffsetY, s.particleRadius / 2, 0, 2 * Math.PI, !0),
h.closePath(), h.fill(), h.beginPath();
for (var t = y.length - 1; t > this.stackPos; t--) {
var e = y[t], i = this.position.x - e.position.x, a = this.position.y - e.position.y;
Math.sqrt(i * i + a * a).toFixed(2) < s.proximity &&
(h.moveTo(this.position.x + this.parallaxOffsetX, this.position.y + this.parallaxOffsetY),
s.curvedLines ? h.quadraticCurveTo(Math.max(e.position.x, e.position.x),
Math.min(e.position.y, e.position.y), e.position.x + e.parallaxOffsetX, e.position.y + e.parallaxOffsetY)
: h.lineTo(e.position.x + e.parallaxOffsetX, e.position.y + e.parallaxOffsetY))
}
h.stroke(), h.closePath()
}, p.prototype.updatePosition = function () {
s.parallax && (S ? (x = (f - 0) / 60 * (X - -30) + 0, m = (c - 0) / 60 * (Y - -30) + 0) : (x = g, m = w),
this.parallaxTargX = (x - f / 2) / (s.parallaxMultiplier * this.layer),
this.parallaxOffsetX += (this.parallaxTargX - this.parallaxOffsetX) / 10,
this.parallaxTargY = (m - c / 2) / (s.parallaxMultiplier * this.layer),
this.parallaxOffsetY += (this.parallaxTargY - this.parallaxOffsetY) / 10);
var t = i.offsetWidth, e = i.offsetHeight;
switch (s.directionX) {
case "left": this.position.x + this.speed.x + this.parallaxOffsetX < 0 && (this.position.x = t - this.parallaxOffsetX); break;
case "right": this.position.x + this.speed.x + this.parallaxOffsetX > t && (this.position.x = 0 - this.parallaxOffsetX); break;
default: (this.position.x + this.speed.x + this.parallaxOffsetX > t || this.position.x + this.speed.x + this.parallaxOffsetX < 0)
&& (this.speed.x = -this.speed.x)
}
switch (s.directionY) {
case "up": this.position.y + this.speed.y + this.parallaxOffsetY < 0 && (this.position.y = e - this.parallaxOffsetY); break;
case "down": this.position.y + this.speed.y + this.parallaxOffsetY > e && (this.position.y = 0 - this.parallaxOffsetY); break;
default: (this.position.y + this.speed.y + this.parallaxOffsetY > e || this.position.y + this.speed.y + this.parallaxOffsetY < 0)
&& (this.speed.y = -this.speed.y)
}
this.position.x += this.speed.x, this.position.y += this.speed.y
}, p.prototype.setStackPos = function (t) { this.stackPos = t }, function () {
if (u) {
(d = e.createElement("canvas")).className = "pg-canvas", d.style.display = "block",
i.insertBefore(d, i.firstChild), h = d.getContext("2d"), o();
for (var a = Math.round(d.width * d.height / s.density), n = 0; a > n; n++) {
var f = new p;
f.setStackPos(n), y.push(f)
}
t.addEventListener("resize", (function () {
! function () {
o();
for (var t = i.offsetWidth, e = i.offsetHeight, a = y.length - 1; a >= 0; a--)(y[a].position.x > t || y[a].position.y > e)
&& y.splice(a, 1);
var n = Math.round(d.width * d.height / s.density);
if (n > y.length) for (; n > y.length;) {
var r = new p;
y.push(r)
} else n < y.length && y.splice(n);
for (a = y.length - 1; a >= 0; a--) y[a].setStackPos(a)
}()
}), !1), e.addEventListener("mousemove", (function (t) { g = t.pageX, w = t.pageY }), !1), S
&& t.addEventListener("deviceorientation", (function () {
Y = Math.min(Math.max(-event.beta, -30), 30), X = Math.min(Math.max(-event.gamma, -30), 30)
}), !0), r(), l("onInit")
}
}(), {
option: function (t, e) { return e ? void (s[t] = e) : s[t] },
destroy: function () { d.parentNode.removeChild(d), l("onDestroy"), n && n(i).removeData("plugin_" + a) },
start: function () { M = !1, r() },
pause: function () { M = !0 }
}
}
var a = "particleGround", n = t.jQuery;
t[a] = function (t, e) { return new i(t, e) }, t[a].defaults = {
minSpeedX: 0.1, maxSpeedX: 0.75, minSpeedY: 0.1, maxSpeedY: 0.75, directionX: "center", directionY: "center", density: 1e4,
dotColor: "#dddddd", lineColor: "#dddddd", particleRadius: 7, lineWidth: 1, curvedLines: !1, proximity: 100, parallax: !0,
parallaxMultiplier: 5, onInit: function () { }, onDestroy: function () { }
}, n && (n.fn[a] = function (t) {
if ("string" == typeof arguments[0]) {
var e, s = arguments[0], o = Array.prototype.slice.call(arguments, 1);
return this.each((function () {
n.data(this, "plugin_" + a) && "function" == typeof n.data(this, "plugin_" + a)[s]
&& (e = n.data(this, "plugin_" + a)[s].apply(this, o))
})), void 0 !== e ? e : this
}
return "object" != typeof t && t ? void 0 : this.each((function () { n.data(this, "plugin_" + a) || n.data(this, "plugin_" + a, new i(this, t)) }))
})
}(window, document), function () {
for (var t = 0, e = ["ms", "moz", "webkit", "o"], i = 0; i < e.length && !window.requestAnimationFrame; ++i)
window.requestAnimationFrame = window[e[i] + "RequestAnimationFrame"], window.cancelAnimationFrame = window[e[i] + "CancelAnimationFrame"]
|| window[e[i] + "CancelRequestAnimationFrame"];
window.requestAnimationFrame || (window.requestAnimationFrame = function (e) {
var i = (new Date).getTime(), a = Math.max(0, 16 - (i - t)), n = window.setTimeout((function () { e(i + a) }), a);
return t = i + a, n
}), window.cancelAnimationFrame || (window.cancelAnimationFrame = function (t) { clearTimeout(t) })
}(), particleGround(document.getElementById("particles-foreground"), {
dotColor: "rgba(255, 255, 255, 1)", lineColor: "rgba(255, 255, 255, 0.1)", minSpeedX: 0.25, maxSpeedX: 0.75, minSpeedY: 0.25, maxSpeedY: 0.75,
density: 5e4, curvedLines: !1, proximity: 250, parallaxMultiplier: 10, particleRadius: 4
}), particleGround(document.getElementById("particles-background"), {
dotColor: "rgba(255, 255, 255, 0.5)", lineColor: "rgba(255, 255, 255, 0.1)", minSpeedX: 0.075, maxSpeedX: 0.25, minSpeedY: 0.075, maxSpeedY: 0.25,
density: 3e4, curvedLines: !1, proximity: 20, parallaxMultiplier: 20, particleRadius: 2
});
Thanks for visiting