Week 7: Sliders & Animated Menus
To Do This Week:
Assignments:
- Slider/Menu Site (5%) — mostly in class, due end of the week — no AI-generated code (Due 10/7)
You'll receive a provided HTML/CSS structure containing an image slider and an animated navigation menu. Your task is to write the JavaScript that makes the interface work — and to be able to explain every part of it.
Read (Optional!): Chapters from Eloquent JavaScript:
- Handling Events (review)
- The Document Object Model (review)
Upcoming Assignments
- JavaScript Codecademy #2 (10%) (Due Week 8 — 10/14)
Module Notes
This week you stop thinking only as a programmer and start thinking as an interaction designer. A slider isn't just a technical puzzle — it's a small experience. Someone arrives, wants to move through a set of images, and every choice you make (how they advance, what happens at the ends, how the motion feels) shapes whether that experience is pleasant or frustrating.
Treat this as a portfolio piece. A well-made slider is one of the most common things you'll be asked to build in the field, and a beautifully considered one is a genuine showpiece for interaction design. Choose content you'd be proud to show, and design it as if a studio were reviewing it.
What is a slider, really?
Underneath the animation, every slider is the same idea: a list of items and a pointer to the current one. "Next" moves the pointer forward, "Previous" moves it back, and the interface shows whatever the pointer is on. Almost all the logic is about managing that one number — the index.
let currentIndex = 0; // which slide are we on?
const slides = [...]; // the list of slides
// show slides[currentIndex]
Designing for the User
Before you write code, make design decisions. These are the questions a studio would ask:
- What happens at the ends? Does "Next" on the last slide loop back to the first (a carousel), or stop and disable the button? Both are valid — decide on purpose.
- Is there feedback? Dots, a counter (3 / 8), or a caption tell the user where they are.
- How does motion feel? A CSS transition on the change makes it read as one continuous experience instead of a jump cut. Speed and easing set the mood.
- Can they navigate directly? Clickable dots or thumbnails let users jump, not just step.
- Is it usable by keyboard? Arrow keys are a small, professional touch (
keydown+e.key). - Does the menu clarify or decorate? An animated menu should make navigation clearer, not just move for its own sake.
Content Ideas
Pick a subject with real images and a reason to be seen in sequence. Strong choices:
- Art gallery — a curated set of paintings, photographs, or digital work, each with a title and caption.
- Travel photos — a journey through a place, ordered so the sequence tells a small story.
- Craft / process — the stages of making something (ceramics, printmaking, cooking, a build), where order genuinely matters.
- Portfolio reel — your own creative work, framed the way you'd present it to a client.
- Product showcase — a small collection presented cleanly, like a shop's featured items.
- Before / after — restorations, edits, transformations — sequence carries meaning.
- Zine or comic — panels or pages advanced one at a time.
Whatever you choose, gather real images first. Placeholder gray boxes make it impossible to judge the experience.
In-class Exercise:
Slider Starter (HTML + CSS provided — you write the JS)Slider Demo (one completed example to study)
- track a current index
- previous / next controls
- show the right slide
- loop or clamp at the ends
- update a counter or dots
- toggle an animated menu
The Core Slider Logic
1. Set up state
State is just the variables that describe "where we are right now."
const slides = document.querySelectorAll(".slide");
let currentIndex = 0;
2. A function that shows the current slide
Write one function whose only job is to make the page match currentIndex. Call it whenever the index changes. This keeps your logic in one place.
function showSlide(index) {
// hide every slide
slides.forEach(function (slide) {
slide.classList.remove("active");
});
// show only the current one
slides[index].classList.add("active");
}
3. Next and Previous change the index
function nextSlide() {
currentIndex = currentIndex + 1;
// loop back to the start if we went past the end
if (currentIndex >= slides.length) {
currentIndex = 0;
}
showSlide(currentIndex);
}
function prevSlide() {
currentIndex = currentIndex - 1;
// loop to the end if we went before the start
if (currentIndex < 0) {
currentIndex = slides.length - 1;
}
showSlide(currentIndex);
}
Looping vs stopping: the if checks above create a carousel that wraps around. To stop at the ends instead, remove the wrap and disable the button when the index reaches 0 or the last slide.
4. Wire the buttons
document.getElementById("nextBtn")
.addEventListener("click", nextSlide);
document.getElementById("prevBtn")
.addEventListener("click", prevSlide);
5. (Optional) keyboard, dots, and a counter
// arrow-key navigation
document.addEventListener("keydown", function (e) {
if (e.key === "ArrowRight") nextSlide();
if (e.key === "ArrowLeft") prevSlide();
});
The Animated Menu
The menu reuses everything from Week 6: a click listener that toggles a class, and a CSS transition that animates the result. The JavaScript stays simple; the CSS carries the motion.
const menuBtn = document.getElementById("menuBtn");
const menu = document.getElementById("menu");
menuBtn.addEventListener("click", function () {
menu.classList.toggle("open");
});
/* CSS does the animation */
#menu { transform: translateX(-100%); transition: transform 0.35s ease; }
#menu.open { transform: translateX(0); }
Slider/Menu Site: 5% DUE: 10/7
You will receive a provided HTML and CSS structure containing an image slider and animated navigation menu. Your task is to write the JavaScript that makes the interface work.
This is primarily a logic and problem-solving project. You should be able to explain how each event, function, variable, and state change contributes to the slider and menu behavior. Think as an interaction designer: this is a showpiece for your portfolio.
Minimum Requirements
- Working previous and next controls
- Correct image or content indexing
- A functional animated navigation menu
- Clear organization using functions and variables
- Numbered logic steps in a comment before the script
- No frameworks, libraries, or AI-generated code
Logic Steps (required)
At the top of your <script>, before any code, write your numbered logic steps as a commented list. For example:
/*
1. Select all the slides and store the current index (start at 0).
2. Write showSlide(index): hide all slides, show the one at index.
3. nextSlide(): add 1 to the index; if past the end, loop to 0; showSlide.
4. prevSlide(): subtract 1; if below 0, loop to the last; showSlide.
5. Add click listeners on the next and prev buttons.
6. Toggle the menu open/closed on the menu button click.
*/
Workshop rhythm this week
- Tuesday: sliders as an experience — examples, design decisions, and starting your logic steps.
- Thursday: build in class. Get the core index logic working first, then add polish (dots, counter, keyboard, easing).
- Keep the Console open. Log
currentIndexon every change to confirm the pointer is where you expect. - You may use Google and documentation for specific syntax. No AI-generated code.