ÌìÃÀ´«Ã½
← Back
Editing: 4888e2511ff98d2bac541f0a098404cecb8c8a40.php
<style> .hero-body { position: relative; background-image: linear-gradient( to left, #003b81, #342659, #311835, #200f19, #000000 ); height: 500px; } #tsparticles { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 0; } .bg-image-particles-swic { width: 100vw; height: 499px; display: flex; justify-content: flex-end; align-items: center; } .sub-hero { margin: 0; } .sub-hero .alert-on { margin: 0; } .bg-image-particles-swic > img { position: absolute; width: 40%; height: 40%; padding: 10px; } </style> <?php $__env->startSection('content'); ?> <?php while(have_posts()): ?> <?php the_post() ?> <?php echo $__env->make('partials.page-header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?> <?php echo $__env->make('partials.mbmodules.page-sub-title', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?> <?php echo $__env->make('partials.content-page', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?> <?php endwhile; ?> <script> const canvas = document.getElementById("canvas1"); const ctx = canvas.getContext("2d"); let width = document.querySelector('.hero-body').clientWidth; let height = document.querySelector('.hero-body').clientHeight; canvas.width = width; canvas.height = height; let swicLogo = document.querySelector('.bg-image-particles-swic'); let subHeroContent = document.querySelector('.sub-hero-content'); let logoPosition = document.querySelector('.bg-image-particles-swic > img').getBoundingClientRect(); const logoX = logoPosition.x; const logoY = logoPosition.y - 240; const logoWidth = logoPosition.width; const logoHeight = logoPosition.height; let particlesArray; // get mouse position let mouse = { x: null, y: null, radius: (canvas.height / 85) * (canvas.width / 85) }; // get mouse coordinates anywhere inside the banner canvas.addEventListener("mousemove", function (event) { mouse.x = event.x; mouse.y = event.y - 240; }); swicLogo.addEventListener("mousemove", function (event) { mouse.x = event.x; mouse.y = event.y - 240; }); subHeroContent.addEventListener("mousemove", function (event) { mouse.x = event.x; mouse.y = event.y - 240; }); // create particle class Particle { constructor(x, y, directionX, directionY, size, color) { this.x = x; this.y = y; this.directionX = directionX; this.directionY = directionY; this.size = size; this.color = color; } // method to draw individual particle draw() { ctx.beginPath(); // cord x - cord y - radius - startAngle - endAngle - anticlockwise? ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false); ctx.fillStyle = "#FFFFFF"; ctx.fill(); } // check particle position, check mouse position, move the particle, draw the perticle update() { // check if particle is still within canvas if (this.x > canvas.width || this.x < 0) { this.directionX = -this.directionX; } if (this.y > canvas.height || this.y < 0) { this.directionY = -this.directionY; } // check if particles collide with logo if(this.x > logoX && this.x < logoX + logoWidth) { this.directionX = -this.directionX; } if(this.y > logoY && this.y < logoY + logoHeight) { this.directionY = -this.directionY; } // check collision detection - mouse position / particle position let dx = mouse.x - this.x; let dy = mouse.y - this.y; let distance = Math.sqrt(dx * dx + dy * dy); if (distance < mouse.radius + this.size) { if (mouse.x < this.x && this.x < canvas.width - this.size * 10) { this.x += 10; } if (mouse.x > this.x && this.x > this.size * 10) { this.x -= 10; } if (mouse.y < this.y && this.y < canvas.height - this.size * 10) { this.y += 10; } if (mouse.y > this.y && this.y > this.size * 10) { this.y -= 10; } } // move particles this.x += this.directionX * 0.35; this.y += this.directionY * 0.35; this.draw(); } } // create particle array function init() { particlesArray = []; let numberOfParticles = (canvas.height * canvas.width) / 3000; for (let i = 0; i < numberOfParticles; i++) { let size = Math.random() * 2 + 1; let x = Math.random() * (innerWidth - size * 2 - size * 2) + size * 2; let y = Math.random() * (innerHeight - size * 2 - size * 2) + size * 2; let directionX = Math.random() * 5 - 2.5; let directionY = Math.random() * 5 - 2.5; let color = "#ffffff"; //check that particles coordinates are drawn outside of logo if ( !( x > logoX && y > logoY && x < logoX + logoWidth && y < logoY + logoHeight ) ) { particlesArray.push( new Particle(x, y, directionX, directionY, size, color) ); } } } // check if particles are close enough to draw a line between them function connect() { let opacityValue = 1; for (let a = 0; a < particlesArray.length; a++) { for (let b = 0; b < particlesArray.length; b++) { let distance = (particlesArray[a].x - particlesArray[b].x) * (particlesArray[a].x - particlesArray[b].x) + (particlesArray[a].y - particlesArray[b].y) * (particlesArray[a].y - particlesArray[b].y); if (distance < (canvas.width / 8) * (canvas.height / 8)) { opacityValue = 1 - distance / 18000; ctx.strokeStyle = "rgba(134,158,255," + opacityValue + ")"; ctx.lineWidth = 0.5; ctx.beginPath(); ctx.moveTo(particlesArray[a].x, particlesArray[a].y); ctx.lineTo(particlesArray[b].x, particlesArray[b].y); ctx.stroke(); } } } } function animate() { requestAnimationFrame(animate); ctx.clearRect(0, 0, width, height); for (let i = 0; i < particlesArray.length; i++) { particlesArray[i].update(); } connect(); } window.addEventListener("resize", function () { canvas.width = width; canvas.height = height; mouse.radius = (canvas.width / 80) * (canvas.height / 80); let logoPosition = document.querySelector('.bg-image-particles-swic > img').getBoundingClientRect(); const logoX = logoPosition.x; const logoY = logoPosition.y - 240; const logoWidth = logoPosition.width; const logoHeight = logoPosition.height; init(); }); canvas.addEventListener("mouseout", function () { mouse.x = undefined; mouse.y = undefined; }); init(); animate(); </script> <?php $__env->stopSection(); ?> <?php echo $__env->make('layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
Save File
Cancel