Carousels & Lightbox

Six components for media and progress presentation. The carousel is built on native scroll-snap - smooth on touch, no Slick or Swiper-style libraries. The bar at the very top of this page is a live example of the reading bar - scroll to see it.

1. What to choose

Component When What it's built on
.carousel Several cards/slides to scroll through horizontally. scroll-snap + JS (arrows, dots)
.carousel-bg-sync A hero with a full-screen background that changes per slide. Same as the carousel + IntersectionObserver
[data-lightbox] Full-screen zoom on photos from a thumbnail gallery. JS builds the entire modal - you only write attributes
.nav-filters Filtering a grid of items (portfolio, gallery) with no reload. JS + state classes (.is-hidden)
.progress A single progress bar with a static value (skills, statistics). Pure CSS, value via style="width:…"
.progress-container-fixed A READING progress bar for the whole page, pinned to the top. The molique-script.js core, listening for scroll

2. Carousel

You set a single slide's width yourself via CSS (min-width: 100% - one slide per screen, 50% - two at once, and so on). The script fills in the rest: it generates pagination dots (as long as there's more than one slide and you haven't provided your own), it handles the arrows, and it highlights the active dot via IntersectionObserver.

<div class="carousel">
  <button class="carousel-nav carousel-prev">‹</button>
  <button class="carousel-nav carousel-next">›</button>

  <div class="carousel-track">
    <!-- min-width controls how many slides are visible at once -->
    <div class="carousel-slide" style="min-width: 100%;">
      <div class="card">Slide 1 content</div>
    </div>
    <div class="carousel-slide" style="min-width: 100%;">
      <div class="card">Slide 2 content</div>
    </div>
  </div>
</div>
<!-- .carousel-dots generates itself below -->
Class What it does
.carousel Wrapper. position: relative - an anchor for the arrows.
.carousel-track overflow-x: auto; scroll-snap-type: x mandatory; - the actual scrolling mechanism.
.carousel-slide scroll-snap-align: start. Width is yours to set, via min-width.
.carousel-nav / -prev / -next The round arrows. Optional - the carousel still works via gesture/scroll without them.
.carousel-dots / .carousel-dot Generated automatically by the script when there's more than one slide and there isn't already a .carousel-dots in the markup. The active dot gets .is-active.

3. Hero Carousel (Background Sync)

A variant where the whole container's background smoothly changes along with the currently visible slide - the same IntersectionObserver that highlights the dots also sets the container's background-image based on the active slide's data-bg.

<div class="carousel carousel-bg-sync">
  <div class="carousel-bg-overlay"></div>

  <div class="carousel-track">
    <!-- data-bg defines the background of THIS specific slide -->
    <div class="carousel-slide" data-bg="img/slide1.jpg">
      <h2>Heading 1</h2>
    </div>
    <div class="carousel-slide" data-bg="img/slide2.jpg">
      <h2>Heading 2</h2>
    </div>
  </div>
</div>
Class / attribute What it does
.carousel-bg-sync A modifier on .carousel. Sets a minimum height and prepares the background for background-image.
data-bg On each .carousel-slide - the background photo's address for THIS slide. Without it, the background simply won't change when this slide comes into view (the previous one stays).
.carousel-bg-overlay A semi-transparent overlay above the background - keeps text readable.

Arrows show on hover only

In this variant, the navigation arrows are invisible until the cursor is over the carousel - consistent with the full-screen, "clean" character of a hero section. On touch they stay invisible (navigation there is a swipe gesture).

4. Lightbox gallery

The whole modal (background, counter, arrows, close button) is built by the script itself on first use - you don't write any of the .lightbox-* classes by hand. Your markup is nothing but links with two data attributes.

<!-- data-lightbox activates the script, data-gallery groups photos together -->
<a href="large-1.jpg" data-lightbox data-gallery="portfolio">
  <img src="thumb-1.jpg" alt="Photo 1">
</a>
<a href="large-2.jpg" data-lightbox data-gallery="portfolio">
  <img src="thumb-2.jpg" alt="Photo 2">
</a>
<a href="photo.jpg" data-lightbox>
  <img src="thumbnail.jpg" alt="…">
</a>
Attribute What it does
data-lightbox On an <a>. Activates the script; the link's href is the full-size photo.
data-gallery Groups links with the same value into a single gallery with a counter and arrows. Without it, every link is its own single-item "gallery".

Navigation: mouse, touch, keyboard

On-screen arrows, swipe gestures on touch, and - inside the open modal - ←/→ to change photo and Esc to close. On opening, focus jumps to the close button and returns to the clicked thumbnail once closed.

Structure of the generated modal

You don't write these classes in your own HTML (see pitfall #2), but they're useful when you want to override the modal's look with your own CSS.

Class What it is
.lightbox-overlay The modal's entire dark background.
.lightbox-content The wrapper around the enlarged photo.
.lightbox-top-bar The top bar with the counter and close button.
.lightbox-counter The "2 / 5" text. Hidden when the gallery only has one photo.
.lightbox-close The × button in the top-right corner.
.lightbox-nav / -prev / -next The arrows on either side. Also hidden for a single-item gallery.

5. Portfolio filters

A menu that filters a grid of items with no page reload and no server requests - pure class manipulation in the DOM.

Website 1
Ad 1
Website 2
<!-- Filter menu -->
<ul class="nav-filters">
  <li><button class="is-active" data-filter="all">All</button></li>
  <li><button data-filter="www">Websites</button></li>
</ul>

<!-- Item container - MUST come right after the menu, see pitfall #1 -->
<div class="grid-auto">
  <div class="filter-item" data-category="www">Project 1</div>
  <div class="filter-item" data-category="ads">Project 2</div>
</div>
Class / attribute What it does
.nav-filters On a <ul>. Buttons inside - any number of them.
data-filter On every button. The value "all" shows everything, any other value shows only the matching category.
.filter-item / data-category On every filtered item. The data-category value is compared against the clicked button's data-filter.
.is-hidden / .is-animated Applied by the script. .is-hidden hides a non-matching item (display: none); .is-animated plays a short "pop in" for matching items.

6. Progress bars

A static bar for presenting a value - skills, statistics, resource usage. Zero JS.

Project progress 85%
SEO optimization 60%
Server usage 92%
<div class="progress-label">
  <span>Project progress</span>
  <span>85%</span>
</div>
<div class="progress">
  <div class="progress-bar bg-success" style="width: 85%;"></div>
</div>
Class What it does
.progress The bar's track - thin, rounded, overflow: hidden.
.progress-bar The fill. Width via style="width: X%". Color - any background class (.bg-success, .bg-danger…).
.progress-label A row of label + value above the bar. Optional.

7. Reading bar

A thin bar pinned to the top of the screen, growing as you scroll. The one at the very top of this page is real - handling lives permanently in the molique-script.js core (like the admin panel's sidebar toggle), not in a separate module.

<!-- Right after opening <body>, before the rest of the content -->
<div class="progress-container-fixed">
  <div class="progress-bar-reading"></div>
</div>
Class What it does
.progress-container-fixed position: fixed, top of the screen, above the navigation. Invisible on its own (transparent background).
.progress-bar-reading The actual bar. Width is updated inside requestAnimationFrame, proportional to the scroll position.

8. Pitfalls

1 The .filter-item container in the wrong DOM position

The script looks for the items to filter via navFilters.nextElementSibling - the container with the .filter-items must be a direct sibling of .nav-filters in the code, right after it. Inserting anything in between (e.g. a descriptive paragraph) makes the buttons stop filtering anything, with no console error.

2 Writing .lightbox-* classes by hand

The entire lightbox modal (.lightbox-overlay, .lightbox-content, buttons…) is created by the script the first time a [data-lightbox] is clicked, and appended to the end of <body>. Writing this structure by hand in your HTML does nothing - and if you happen to give the class .lightbox-overlay to something else, the script will treat it as an already-existing modal and start appending to it.

3 .progress-bar and .progress-bar-reading animate width

Both components run a transition on the width property - convenient (width is a natural measure of a percentage), but this is one of the few deliberate exceptions to this framework's "only animate transform/opacity" rule: with very frequent updates (a reading bar during fast scrolling) this can cost more frames than an equivalent built on transform: scaleX(). In practice, for a single bar the effect is unnoticeable - worth remembering only once there are many animated bars at once on the same screen.

4 A slide with no data-bg in the Background Sync variant

If a given .carousel-slide has no data-bg attribute, scrolling to it does NOT clear the background - the previous slide's image stays. If you deliberately want an empty background on some slide, set data-bg="" explicitly instead of omitting the attribute.

9. Related pages