Skip to content

Commit

Permalink
Improve custom cursor on project details page
Browse files Browse the repository at this point in the history
Cannot make it work over YouTube iframe. Instead just make it disappear and allow the default pointer cursor when hovering the iframe.
  • Loading branch information
Pete-Fowler committed Sep 20, 2024
1 parent 04db1af commit 430db3e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/ui/YouTubeEmbed.astro
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ const { videoId, width = 560, height = 315 } = Astro.props;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
</style>
11 changes: 11 additions & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ const { site_title, site_description, email, socials } = Astro.props;
const cursorY = event.clientY + window.scrollY;
cursor.style.left = `${cursorX}px`;
cursor.style.top = `${cursorY}px`;
});

const iframe = document.querySelector('.iframe-box iframe');
iframe?.addEventListener('mouseenter', () => {
cursor.style.display = 'none';
});

iframe?.addEventListener('mouseleave', () => {
cursor.style.display = 'block';
});
});


</script>
26 changes: 26 additions & 0 deletions src/layouts/SubLayout.astro → src/layouts/ProjectLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,29 @@ const { site_title, site_description, email, socials } = Astro.props;
<Footer />
</body>
</html>

<script>
window.addEventListener('load', () => {
const cursor = document.createElement('div');
cursor.className = 'custom-cursor';
document.body.appendChild(cursor);

document.addEventListener('mousemove', (event) => {
const cursorX = event.clientX + window.scrollX;
const cursorY = event.clientY + window.scrollY;
cursor.style.left = `${cursorX}px`;
cursor.style.top = `${cursorY}px`;
});

const iframe = document.querySelector('.iframe-box iframe');
iframe?.addEventListener('mouseenter', () => {
cursor.style.display = 'none';
});

iframe?.addEventListener('mouseleave', () => {
cursor.style.display = 'block';
});
});


</script>
2 changes: 1 addition & 1 deletion src/pages/projects/[slug].astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import { parseSiteConfig } from "../../config";
import SubLayout from "../../layouts/SubLayout.astro";
import SubLayout from "../../layouts/ProjectLayout.astro";
import { getCollection } from "astro:content";
export async function getStaticPaths() {
Expand Down
2 changes: 2 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ a,
input,
textarea,
select,
img,
div#player,
button:hover,
a:hover {
cursor: none !important;
Expand Down

0 comments on commit 430db3e

Please sign in to comment.