Skip to content

Commit

Permalink
Added Follow Along Cursor (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Praneeth-2602 authored Aug 10, 2024
1 parent 8b902ce commit 20bd884
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Components/Cursors/Follow-Along-Cursor/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Cursor</title>
<link rel="stylesheet" href="style.css">
</head>

<body>
<div class="cursor">
<div class="cursor__ball cursor__ball--big ">
<svg height="30" width="30">
<circle cx="15" cy="15" r="12" stroke-width="0"></circle>
</svg>
</div>
<div class="cursor__ball cursor__ball--small">
<svg height="10" width="10">
<circle cx="5" cy="5" r="4" stroke-width="0"></circle>
</svg>
</div>
</div>

<div class="left">
<h1>Hello</h1>
<p>Check out this link:</p>
<a class="hoverable">Hover meh</a>
</div>

<div class="right">
<h1>Hello</h1>
<p>Check out this link:</p>
<a class="hoverable">Hover meh</a>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
<script src="script.js"></script>
</body>

</html>
25 changes: 25 additions & 0 deletions Components/Cursors/Follow-Along-Cursor/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const $bigBall = document.querySelector('.cursor__ball--big');
const $smallBall = document.querySelector('.cursor__ball--small');
const $hoverables = document.querySelectorAll('.hoverable');

// Listeners
document.body.addEventListener('mousemove', onMouseMove);
for (let i = 0; i < $hoverables.length; i++) {
$hoverables[i].addEventListener('mouseenter', onMouseHover);
$hoverables[i].addEventListener('mouseleave', onMouseHoverOut);
}

// Move the cursor
function onMouseMove(e) {
gsap.to($bigBall, { duration: 0.4, x: e.pageX - 15, y: e.pageY - 15 });
gsap.to($smallBall, { duration: 0.1, x: e.pageX - 5, y: e.pageY - 5 });
}

// Hover an element
function onMouseHover() {
gsap.to($bigBall, { duration: 0.3, scale: 4 });
}

function onMouseHoverOut() {
gsap.to($bigBall, { duration: 0.3, scale: 1 });
}
60 changes: 60 additions & 0 deletions Components/Cursors/Follow-Along-Cursor/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
body {
height: 100vh;
background: #010101;
cursor: none;
margin: 0;
display: flex;
font-family: monospace;
}

h1,
p,
a {
color: #fff;
}

a {
border-bottom: 2px solid #fff;
padding: 10px 0;
margin-top: 25px;
}

.cursor {
pointer-events: none;
}

.cursor__ball {
position: fixed;
top: 0;
left: 0;
mix-blend-mode: difference;
z-index: 1000;
}

.cursor__ball circle {
fill: #f7f8fa;
}

.left,
.right {
height: 100%;
width: 50%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.right {
background: #fff;
}

.right a {
border-bottom: 2px solid #000;
}

.right h1,
.right p,
.right a {
color: #000;
}
13 changes: 13 additions & 0 deletions assets/html_files/cursors.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ <h1>Pulsating Custom Cursor</h1>
</a>
</div>
</div>
<div class="box">
<h1>Follow Along Cursor</h1>
<div class="preview">
<a href="../../Components/Cursors/Follow-Along-Cursor/index.html" title="Live Preview" target="_blank">
<img src="../images/link.png">
</a>
</div>
<div class="source">
<a href="https://github.com/Rakesh9100/Beautiify/tree/main/Components/Cursors/Follow-Along-Cursor" title="Source Code" target="_blank">
<img src="../images/github.png">
</a>
</div>
</div>
</div>
</section>

Expand Down

0 comments on commit 20bd884

Please sign in to comment.