JSFiddle - React, Tailwind, and code Playground
by masmiguel
HTML
<canvas id="canvas"></canvas>
<!--h1>FLASH</h1-->
<div class="imgborder s10">
<img src="http://veggyses-cp509.webprestashop.com/prestashop/img/pack-cilene-logo-1476971830.jpg" >
</div>
CSS
body {
background: white;
margin: 0rem;
min-height: 100vh;
font-family: Futura, sans-serif;
}
#canvas, #text {
position: absolute;
display: block;
top: 0;
left: 0;
z-index: -1;
}
#text {
min-height: 100vh;
width: 100vw;
z-index: 1;
color: #fff;
text-transform: uppercase;
font-size: 8vmin;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
#text h1 {
opacity: 0.9
}
.s10:after {
z-index: -1;
position: absolute;
content: "Veggys";
bottom: 15px;
right: 10px;
left: auto;
width: 50%;
top: 80%;
max-width:300px;
background: #777;
-webkit-box-shadow: 0 15px 10px #777;
-moz-box-shadow: 0 15px 10px #777;
box-shadow: 0 15px 10px #777;
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-o-transform: rotate(3deg);
-ms-transform: rotate(3deg);
transform: rotate(3deg);
}
.imgborder {
display:inline-block;
position:relative;
border:1px solid #ccc;
padding:5px;
top:50%;
background:#f2f2f2;
z-index:-10;
}
JavaScript
let resizeReset = function() {
w = canvasBody.width = window.innerWidth;
h = canvasBody.height = window.innerHeight;
}
const opts = {
particleColor: "rgb(224,78,57)",
lineColor: "rgb(224,78,57)",
particleAmount: 30,
defaultSpeed: 1.5,
variantSpeed: 1,
defaultRadius: 2,
variantRadius: 2,
linkRadius: 200,
};
window.addEventListener("resize", function(){
deBouncer();
});
let deBouncer = function() {
clearTimeout(tid);
tid = setTimeout(function() {
resizeReset();
}, delay);
};
let checkDistance = function(x1, y1, x2, y2){
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
};
let linkPoints = function(point1, hubs){
for (let i = 0; i < hubs.length; i++) {
let distance = checkDistance(point1.x, point1.y, hubs[i].x, hubs[i].y);
let opacity = 1 - distance / opts.linkRadius;
if (opacity > 0) {
drawArea.lineWidth = 0.5;
drawArea.strokeStyle = `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${opacity})`;
drawArea.beginPath();
drawArea.moveTo(point1.x, point1.y);
drawArea.lineTo(hubs[i].x, hubs[i].y);
drawArea.closePath();
drawArea.stroke();
}
}
}
Particle = function(xPos, yPos){
this.x = Math.random() * w;
this.y = Math.random() * h;
this.speed = opts.defaultSpeed + Math.random() * opts.variantSpeed;
this.directionAngle = Math.floor(Math.random() * 360);
this.color = opts.particleColor;
this.radius = opts.defaultRadius + Math.random() * opts. variantRadius;
this.vector = {
x: Math.cos(this.directionAngle) * this.speed,
y: Math.sin(this.directionAngle) * this.speed
};
this.update = function(){
this.border();
this.x += this.vector.x;
this.y += this.vector.y;
};
this.border = function(){
if (this.x >= w || this.x <= 0) {
this.vector.x *= -1;
}
if (this.y >= h || this.y <= 0) {
this.vector.y *= -1;
}
if (this.x > w) this.x = w;
if (this.y > h) this.y = h;
if (this.x < 0) this.x = 0;
if (this.y < 0) this.y = 0;
};
this.draw = function(){...