-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b902ce
commit 20bd884
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters