Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added animated cursor functionality #327

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions public/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,27 @@ body {
height: 5rem;
z-index: 1000;
}
/* cursor */
.circle {
z-index: 10000;
width: 20px;
height: 20px;
border-radius: 50%;
pointer-events: none;
animation: colors 5s infinite;
position: fixed;
transform: translate(-50%, -50%);
}

.circle::before {
content: "";
position: fixed;
width: 50px;
height: 50px;
opacity: 0.2;
transform: translate(-30%, -30%);
border-radius: 50%;
}
/* navigation bar font size transition styling*/


Expand Down
75 changes: 75 additions & 0 deletions server/views/about.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
</head>

<body class="page-leaderboard">
<div class="circle-container">
<div class="circle" style="background-color: #55a5ea; left: 504px; top: 59px; scale: 1;"></div>
<div class="circle" style="background-color: #55a5ea; left: 504px; top: 59px; scale: 0.95;"></div>
<div class="circle" style="background-color: #55a5ea; left: 504px; top: 59px; scale: 0.9;"></div>
<div class="circle" style="background-color: #55a5ea; left: 504px; top: 59px; scale: 0.9;"></div>
<div class="circle" style="background-color: #3fbcc0c6; left: 504px; top: 59px; scale: 0.85;"></div>
<div class="circle" style="background-color: #3fbcc0c6; left: 504px; top: 59px; scale: 0.85;"></div>
<div class="circle" style="background-color: #3fbcc0c6; left: 504px; top: 59px; scale: 0.85;"></div>
<div class="circle" style="background-color: #3fbcc0c6; left: 504px; top: 59px; scale: 0.85;"></div>
<div class="circle" style="background-color: #fff; left: 504px; top: 59px; scale: 0.8;"></div>
<div class="circle" style="background-color: #fff; left: 504px; top: 59px; scale: 0.8;"></div>
<div class="circle" style="background-color: #fff; left: 504px; top: 59px; scale: 0.8;"></div>
<div class="circle" style="background-color: #fff; left: 504px; top: 59px; scale: 0.8;"></div>
</div>
<!-- Body of the webpage. Background color set inline. -->
<nav class="nav">
<!-- Navigation section. -->
Expand Down Expand Up @@ -327,7 +341,68 @@
</footer>
</body>
<script>
//Custom Cursor

const coords = { x: 0, y: 0 };
const circles = document.querySelectorAll(".circle");

const colors = [
"#55a5ea",
"#55a5ea",
"#55a5ea",
"#55a5ea",
"#55a5ea",
"#55a5ea",
"#55a5ea",
"#55a5ea",
"#3fbcc0c6",
"#3fbcc0c6",
"#3fbcc0c6",
"#3fbcc0c6",
"#3fbcc0c6",
"#3fbcc0c6",
"fff",
"fff",
"fff",
"fff",
"fff",
"fff",
"fff",
];

circles.forEach(function (circle, index) {
circle.x = 0;
circle.y = 0;
circle.style.backgroundColor = colors[index % colors.length];
});

window.addEventListener("mousemove", function (e) {
coords.x = e.clientX;
coords.y = e.clientY;
});

function animateCircles() {
let x = coords.x;
let y = coords.y;

circles.forEach(function (circle, index) {
circle.style.left = x - 12 + "px";
circle.style.top = y - 12 + "px";

circle.style.scale = (circles.length - index) / circles.length;

circle.x = x;
circle.y = y;

const nextCircle = circles[index + 1] || circles[0];
x += (nextCircle.x - x) * 0.3;
y += (nextCircle.y - y) * 0.3;
});

requestAnimationFrame(animateCircles);
}

animateCircles();

document.querySelector('.toggler').addEventListener('click', function () {
document.querySelector('.social-icons').classList.toggle('show-icons');
Expand Down
Loading
Loading