Skip to content

Instantly share code, notes, and snippets.

@hogyzen12
Created February 17, 2023 20:57
Show Gist options
  • Save hogyzen12/706e743f5594605b119740d2d88fb6c1 to your computer and use it in GitHub Desktop.
Save hogyzen12/706e743f5594605b119740d2d88fb6c1 to your computer and use it in GitHub Desktop.
Mousemove Image Gallery
<img class="image" data-index="0" data-status="inactive" src="https://media.discordapp.net/attachments/1064223668516958248/1064224255404953610/gen2_announcement.png?width=1000&height=1000" />
<img class="image" data-index="1" data-status="inactive" src="https://media.discordapp.net/attachments/1064223668516958248/1064224474167259238/METAME_HQ_banner_twitter.png" />
<img class="image" data-index="2" data-status="inactive" src="https://media.discordapp.net/attachments/1064223668516958248/1064225452631265350/unknown.png" />
<img class="image" data-index="3" data-status="inactive" src="https://media.discordapp.net/attachments/1064223668516958248/1064228161971290122/unknown.png" />
<img class="image" data-index="4" data-status="inactive" src="https://media.discordapp.net/attachments/1064223668516958248/1064228290451230830/image0.png?width=976&height=579" />
<img class="image" data-index="5" data-status="inactive" src="https://media.discordapp.net/attachments/1064223668516958248/1074827011136159844/image.png?width=581&height=579" />
<img class="image" data-index="6" data-status="inactive" src="https://shdw-drive.genesysgo.net/HfbS7SkXU3FurmPE5uGJucNiWuJYvbxQXCXJKHLd1oNG/2.png" />
<img class="image" data-index="7" data-status="inactive" src="https://shdw-drive.genesysgo.net/HfbS7SkXU3FurmPE5uGJucNiWuJYvbxQXCXJKHLd1oNG/239.png" />
<img class="image" data-index="8" data-status="inactive" src="https://shdw-drive.genesysgo.net/HfbS7SkXU3FurmPE5uGJucNiWuJYvbxQXCXJKHLd1oNG/54.png" />
<img class="image" data-index="9" data-status="inactive" src="https://shdw-drive.genesysgo.net/HfbS7SkXU3FurmPE5uGJucNiWuJYvbxQXCXJKHLd1oNG/203.png" />
<a id="source-link" class="meta-link" href="https://bridget.pictures" target="_blank">
<i class="fa-solid fa-link"></i>
<span>Source</span>
</a>
<a id="yt-link" class="meta-link" href="https://youtu.be/Jt3A2lNN2aE" target="_blank">
<i class="fa-brands fa-youtube"></i>
<span>3 min tutorial</span>
</a>
const images = document.getElementsByClassName("image");
let globalIndex = 0,
last = { x: 0, y: 0 };
const activate = (image, x, y) => {
image.style.left = `${x}px`;
image.style.top = `${y}px`;
image.style.zIndex = globalIndex;
image.dataset.status = "active";
last = { x, y };
}
const distanceFromLast = (x, y) => {
return Math.hypot(x - last.x, y - last.y);
}
const handleOnMove = e => {
if(distanceFromLast(e.clientX, e.clientY) > (window.innerWidth / 20)) {
const lead = images[globalIndex % images.length],
tail = images[(globalIndex - 5) % images.length];
activate(lead, e.clientX, e.clientY);
if(tail) tail.dataset.status = "inactive";
globalIndex++;
}
}
window.onmousemove = e => handleOnMove(e);
window.ontouchmove = e => handleOnMove(e.touches[0]);
<script src="https://kit.fontawesome.com/944eb371a4.js"></script>
body {
background-color: black;
height: 100vh;
margin: 0px;
overflow: hidden;
}
.image {
width: 40vmin;
position: absolute;
transform: translate(-50%, -50%);
}
.image[data-status="inactive"] {
display: none;
}
.image[data-status="active"] {
display: block;
}}
/* -- YouTube Link Styles -- */
body.menu-toggled > .meta-link > span {
color: rgb(30, 30, 30);
}
#source-link {
bottom: 60px;
}
#source-link > i {
color: rgb(94, 106, 210);
}
#yt-link > i {
color: rgb(239, 83, 80);
}
.meta-link {
align-items: center;
backdrop-filter: blur(3px);
background-color: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
bottom: 10px;
box-shadow: 2px 2px 2px rgba(0, 0, 0, 0.1);
cursor: pointer;
display: inline-flex;
gap: 5px;
left: 10px;
padding: 10px 20px;
position: fixed;
text-decoration: none;
transition: background-color 400ms, border-color 400ms;
z-index: 10000;
}
.meta-link:hover {
background-color: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.meta-link > i, .meta-link > span {
height: 20px;
line-height: 20px;
}
.meta-link > span {
color: white;
font-family: "Rubik", sans-serif;
font-weight: 500;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment