Built a slider for the Projects section

This commit is contained in:
blake committed 2026-02-13 11:00:06 -06:00
1 parent fbd3415c1e
commit 3a4b43ec88
4 files changed
+367 -23

No files matched your search

+67 -16
View File
@@ -20,8 +20,20 @@
}
.project-card {
width: 45rem;
height: 28rem;
width: 42rem;
height: 26rem;
}
.project-track {
height: 54rem;
}
.project-slide.slide-prev {
transform: translate(calc(-50% - 38rem), 0) scale(0.8);
}
.project-slide.slide-next {
transform: translate(calc(-50% + 38rem), 0) scale(0.8);
}
.steps-header {
@@ -78,8 +90,20 @@
}
.project-card {
width: 40rem;
height: 25rem;
width: 35rem;
height: 22rem;
}
.project-track {
height: 50rem;
}
.project-slide.slide-prev {
transform: translate(calc(-50% - 32rem), 0) scale(0.75);
}
.project-slide.slide-next {
transform: translate(calc(-50% + 32rem), 0) scale(0.75);
}
.contact-grid {
@@ -177,7 +201,7 @@
.about-content {
max-width: 90%;
padding: 10rem 0;
padding: 25rem 0;
}
.about-wrapper {
@@ -188,13 +212,33 @@
bottom: -28rem;
}
.project-grid {
grid-template-columns: 1fr;
.project-card {
width: 45rem;
height: 28rem;
}
.project-card {
.project-desc {
max-width: 65rem;
}
.project-slide {
width: 65rem;
height: 40rem;
}
.project-track {
height: 58rem;
}
.project-slide.slide-prev {
transform: translate(calc(-50% - 50rem), 0) scale(0.8);
opacity: 0;
pointer-events: none;
}
.project-slide.slide-next {
transform: translate(calc(-50% + 50rem), 0) scale(0.8);
opacity: 0;
pointer-events: none;
}
.contact-grid {
@@ -297,18 +341,25 @@
/************************/
@media (max-width: 31em) {
.project-card {
width: 55rem;
height: 32rem;
}
.about-content {
padding-bottom: 30rem;
}
.project-card {
width: 42rem;
height: 28rem;
width: 38rem;
height: 24rem;
padding: 2rem;
display: flex;
flex-direction: column;
justify-content: center;
}
.project-desc {
max-width: 38rem;
}
.project-track {
height: 54rem;
}
.contact-grid {
+101 -5
View File
@@ -470,10 +470,107 @@ p {
top: 3rem;
}
.project-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5rem;
.project-carousel {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: 3rem;
width: 100%;
max-width: 160rem;
}
.project-track {
position: relative;
width: 100%;
height: 58rem;
overflow: hidden;
}
.project-slide {
position: absolute;
top: 0;
left: 50%;
display: flex;
flex-direction: column;
align-items: center;
width: 50rem;
transition:
transform 0.6s ease,
opacity 0.6s ease;
will-change: transform, opacity;
}
.project-desc {
text-align: left;
max-width: 50rem;
width: 100%;
margin-top: 2rem;
transition: opacity 0.6s ease;
}
.project-slide.slide-active {
transform: translateX(-50%) scale(1);
opacity: 1;
z-index: 3;
}
.project-slide.slide-prev {
transform: translate(calc(-50% - 44rem), 0) scale(0.8);
opacity: 0.4;
z-index: 2;
}
.project-slide.slide-next {
transform: translate(calc(-50% + 44rem), 0) scale(0.8);
opacity: 0.4;
z-index: 2;
}
.project-slide.slide-prev .project-desc,
.project-slide.slide-next .project-desc {
opacity: 0.15;
}
.project-slide.slide-hidden-left {
transform: translate(calc(-50% - 90rem), 0) scale(0.6);
opacity: 0;
z-index: 1;
pointer-events: none;
}
.project-slide.slide-hidden-right {
transform: translate(calc(-50% + 90rem), 0) scale(0.6);
opacity: 0;
z-index: 1;
pointer-events: none;
}
.project-controls {
display: flex;
gap: 2rem;
}
.project-btn {
background-color: transparent;
border: 3px solid #fff;
color: #fff;
width: 3.5rem;
height: 3.5rem;
border-radius: 50%;
font-size: 2rem;
cursor: pointer;
transition: all 0.3s;
display: flex;
align-items: center;
justify-content: center;
}
.project-btn:hover {
background-color: #ffe642;
border-color: #ffe642;
color: #0b1532;
transform: scale(1.05);
}
.tag {
@@ -500,7 +597,6 @@ p {
.project-card:hover {
box-shadow: 0 1rem 1rem 0 #2d54c7;
transform: scale(1.02);
}
.project-card--1 {
+58 -1
View File
@@ -242,7 +242,9 @@
<h2>Past Projects</h2>
</div>
<img class="astronaut" src="img/astronaut.webp" alt="astronaut" />
<div class="project-grid animate-on-scroll">
<div class="project-carousel animate-on-scroll">
<div class="project-track">
<div class="project-slide">
<a
href="https://valordesignlabs.com"
target="_blank"
@@ -253,6 +255,14 @@
<span class="tag">Shopify</span>
</div>
</a>
<p class="project-desc">
A Shopify store for a first responder merchandise brand. Getting
into the e-commerce side of web development was a blast,
building out product collections for challenge coins, patches,
and more.
</p>
</div>
<div class="project-slide">
<a
href="https://christs-hands.org"
target="_blank"
@@ -263,6 +273,15 @@
<span class="tag">Webflow</span>
</div>
</a>
<p class="project-desc">
My very first client project. Webflow made it easy to get
started while still giving me plenty of room to customize. I
really believe in what this nonprofit is doing for the
community, which made the whole process that much more
rewarding.
</p>
</div>
<div class="project-slide">
<a
href="https://terrytownpuppies.com"
target="_blank"
@@ -273,6 +292,14 @@
<span class="tag">Wix</span>
</div>
</a>
<p class="project-desc">
A site for a family-run puppy breeder with 40+ years of
experience. Wix can be challenging with its limitations, but it
makes it easy for the client to manage on their own. Had a lot
of fun dialing in the color palette on this one.
</p>
</div>
<div class="project-slide">
<a
href="https://hopefoodpantrysc.org"
target="_blank"
@@ -283,6 +310,14 @@
<span class="tag">HTML, CSS, and JS</span>
</div>
</a>
<p class="project-desc">
My first client website built entirely from scratch with HTML,
CSS, and JavaScript. No page builders, no templates, just custom
code. I'm super proud of how this one turned out for a local
food pantry serving the Sioux Center community.
</p>
</div>
<div class="project-slide">
<a
href="https://centralreformed.org"
target="_blank"
@@ -293,6 +328,28 @@
<span class="tag">Wix</span>
</div>
</a>
<p class="project-desc">
Built in Wix so the church staff can easily update content
themselves, which was a big improvement over their old site. Had
a quick turnaround on this one and the team was great to work
with.
</p>
</div>
</div>
<div class="project-controls">
<button
class="project-btn project-btn--prev"
aria-label="Previous project"
>
<img src="img/icons/left-arrow.svg" alt="left arrow icon" />
</button>
<button
class="project-btn project-btn--next"
aria-label="Next project"
>
<img src="img/icons/right-arrow.svg" alt="right arrow icon" />
</button>
</div>
</div>
</section>
+141 -1
View File
@@ -24,7 +24,7 @@ const testimonials = [
},
{
text: "Cosmically Creative built my website exactly how I envisioned it—clean, functional, and professional. They were easy to work with, quick to respond, and clearly cared about getting every detail right. The end result speaks for itself. From our first conversation, they took the time to understand my business and what I needed the site to accomplish. I never felt rushed or out of the loop—updates came regularly, and my feedback was always taken seriously. I'd recommend them to anyone looking for a web developer who actually listens.",
name: "&dash; Ten8Locker",
name: "&dash; Valor Design Labs",
},
];
@@ -80,6 +80,146 @@ document
showSlide(currentSlide + 1);
});
// Project Carousel
const projectTrack = document.querySelector(".project-track");
const projectCards = Array.from(
projectTrack.querySelectorAll(".project-slide"),
);
let currentProject = 0;
let isSliding = false;
const slideClasses = [
"slide-active",
"slide-prev",
"slide-next",
"slide-hidden-left",
"slide-hidden-right",
];
function getPositions(index, direction) {
const total = projectCards.length;
const prev = (index - 1 + total) % total;
const next = (index + 1) % total;
const positions = new Map();
positions.set(index, "slide-active");
positions.set(prev, "slide-prev");
positions.set(next, "slide-next");
for (let i = 0; i < total; i++) {
if (!positions.has(i)) {
if (direction === "next") {
positions.set(i, "slide-hidden-left");
} else if (direction === "prev") {
positions.set(i, "slide-hidden-right");
} else {
positions.set(i, "slide-hidden-left");
}
}
}
return positions;
}
function applyPositions(positions) {
projectCards.forEach((card, i) => {
card.classList.remove(...slideClasses);
card.classList.add(positions.get(i));
});
}
function slideToProject(newIndex, direction) {
if (isSliding || newIndex === currentProject) return;
isSliding = true;
const total = projectCards.length;
const oldPrev = (currentProject - 1 + total) % total;
const oldNext = (currentProject + 1) % total;
const newPrev = (newIndex - 1 + total) % total;
const newNext = (newIndex + 1) % total;
// First: instantly move the incoming card to its off-screen start position
// (no transition) so it can slide in from the correct side
const incoming =
direction === "next" ? projectCards[newNext] : projectCards[newPrev];
if (incoming) {
incoming.style.transition = "none";
incoming.classList.remove(...slideClasses);
incoming.classList.add(
direction === "next" ? "slide-hidden-right" : "slide-hidden-left",
);
// Force reflow so the position applies before the transition kicks in
incoming.offsetHeight;
incoming.style.transition = "";
}
currentProject = newIndex;
const positions = getPositions(newIndex, direction);
applyPositions(positions);
// Unlock after transition finishes
const activeCard = projectCards[newIndex];
const onEnd = () => {
isSliding = false;
activeCard.removeEventListener("transitionend", onEnd);
};
activeCard.addEventListener("transitionend", onEnd);
// Safety fallback
setTimeout(() => {
isSliding = false;
}, 700);
}
// Initial state
applyPositions(getPositions(0, null));
document.querySelector(".project-btn--prev").addEventListener("click", () => {
const total = projectCards.length;
const newIndex = (currentProject - 1 + total) % total;
slideToProject(newIndex, "prev");
});
document.querySelector(".project-btn--next").addEventListener("click", () => {
const total = projectCards.length;
const newIndex = (currentProject + 1) % total;
slideToProject(newIndex, "next");
});
// Project Carousel Swipe Support
let touchStartX = 0;
let touchEndX = 0;
const swipeThreshold = 50;
projectTrack.addEventListener(
"touchstart",
(e) => {
touchStartX = e.changedTouches[0].clientX;
},
{ passive: true },
);
projectTrack.addEventListener(
"touchend",
(e) => {
touchEndX = e.changedTouches[0].clientX;
const diff = touchStartX - touchEndX;
if (Math.abs(diff) > swipeThreshold) {
const total = projectCards.length;
if (diff > 0) {
const newIndex = (currentProject + 1) % total;
slideToProject(newIndex, "next");
} else {
const newIndex = (currentProject - 1 + total) % total;
slideToProject(newIndex, "prev");
}
}
},
{ passive: true },
);
// Scroll Animations
document.addEventListener("DOMContentLoaded", () => {
const observerOptions = { root: null, rootMargin: "0px", threshold: 0.5 };