• Stars
    star
    105
  • Rank 317,139 (Top 7 %)
  • Language
    HTML
  • License
    MIT License
  • Created 3 months ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add next/previous buttons to a horizontal scrollable container.

carouscroll

A web component to add next/previous buttons to a horizontal scrollable container.

Features

  • Interaction compatible with scroll or touch.
  • No layout shift. Make sure you include the CSS snippet!
  • (Optional) Smooth scrolling with scroll-behavior: smooth.
  • (Optional) loop attribute to enable looping around from start/end.
  • (Optional) Next/Previous buttons can be placed anywhere in the document.
  • (Optional) <output> element can accessibly announce the current slide number (out of total number of slides).

Installation

You can install via npm (@zachleat/carouscroll) or download the carouscroll.js JavaScript file manually.

npm install @zachleat/carouscroll --save

Add carouscroll.js to your site’s JavaScript assets.

Usage

First you need to add some critical CSS to your page. These styles are crucial to reduce Layout Shift (CLS), set the aspect ratio of the slides, and to avoid loading loading="lazy" images on off-screen slides.

carou-scroll {
	display: flex;
	overflow-x: scroll;
	overflow-y: hidden;
}
carou-scroll > * {
	min-width: 100%;
	aspect-ratio: 16/9;
}

Next, add the HTML:

<carou-scroll id="my-scroller">
	<div class="demo-slide">1</div>
	<div class="demo-slide">2</div>
	<!-- … -->
</carou-scroll>

That’s it!

Add buttons (optional)

For maximum flexibility, these buttons can be placed anywhere in the document and are tied by an id back to the parent scroller.

Make sure you think about the before/after JavaScript experience here. This component will remove disabled for you but you can add additional styling via your own CSS: carou-scroll:defined {}.

<button type="button" disabled data-carousel-previous="my-scroller">Previous</button>
<button type="button" disabled data-carousel-next="my-scroller">Next</button>

Add output (optional)

This will update (and accessibly announce) a current status element with e.g. Slide 1 of 10 text.

For maximum flexibility, this element can be placed anywhere in the document and is tied by an id back to the parent scroller.

<output data-carousel-output="my-scroller"></output>

Make it loop around (optional)

Add the loop attribute.

<carou-scroll id="my-scroller" loop>

Smooth scrolling CSS (optional)

carou-scroll {
	scroll-behavior: smooth;
}

Add your own scroll snap CSS (optional)

carou-scroll {
	scroll-snap-type: x mandatory;
}
carou-scroll > * {
	scroll-snap-align: center;
}

More Repositories

1

web-font-loading-recipes

A bunch of demos for different web font loading strategies. Companion to https://www.zachleat.com/web/comprehensive-webfonts/
HTML
1,056
star
2

speedlify

Benchmark the web performance and accessibility of sites over time.
JavaScript
899
star
3

BigText

jQuery plugin, calculates the font-size and word-spacing needed to match a line of text to a specific width.
JavaScript
888
star
4

fontfaceonload

A simple utility to execute a callback when a webfont loads.
JavaScript
373
star
5

table-saw

A small web component for responsive <table> elements.
HTML
299
star
6

details-utils

A suite of utilities to add more features to the <details> element.
JavaScript
248
star
7

browser-window

Used in demos as a way to fake a Safari-esque web browser window.
JavaScript
240
star
8

Humane-Dates

Show the difference between a date and now (4 days ago)
JavaScript
186
star
9

zachleat.com

zachleat.com is powered by Eleventy and WebC.
JavaScript
180
star
10

performance-leaderboard

A plugin to run Lighthouse against a set of urls to see which site is the fastest.
JavaScript
96
star
11

postcss-foft-classes

A postcss plugin to automatically add classes for various font loading strategies.
JavaScript
89
star
12

seven-minute-tabs

A minimal no-theme Tabs web component.
JavaScript
84
star
13

filter-container

Filtering visible child elements based on form field values.
HTML
80
star
14

video-radio-star

A lightweight web component helper for HTML5 videos.
HTML
72
star
15

font-family-reunion

Compatibility tables for default local fonts.
HTML
66
star
16

spider-pig

Get a list of local URL links from a root URL.
JavaScript
65
star
17

snow-fall

A web component to add snow to your web site (or to an element on your web site).
JavaScript
65
star
18

announcement-banner

An announcement banner web component.
HTML
48
star
19

speedlify-score

A web component that shows Lighthouse scores via Speedlify.
JavaScript
40
star
20

jQuery-Gravatar

Retrieve a gravatar image dynamically from any e-mail address.
JavaScript
37
star
21

squirminal

The squirminal is a fake antique terminal web component
HTML
34
star
22

hypercard

Web component to add a three-dimensional hover effect to a card.
JavaScript
33
star
23

bench-framework-markdown

A set of scripts to test markdown processing speeds in various site generators/frameworks
TypeScript
33
star
24

queue-code

Allows you to “type” syntax highlighted source code for presentations and screencasts.
JavaScript
30
star
25

infinity-burger

A new kind of hamburger menu
JavaScript
29
star
26

performance-leaderboard-pagespeed-insights

A plugin to run Lighthouse on Pagespeed Insights against a set of urls to see which site is the fastest.
JavaScript
27
star
27

esm-import-transformer

Change import URLs in JavaScript code using import maps. e.g. `import * from "before"` to `import * from "after"`
JavaScript
24
star
28

idea-book

A public dump of ideas for side projects, for public upvoting/downvoting/commenting.
24
star
29

selecthor

A better way to test, learn, and demo CSS selectors
HTML
24
star
30

JavaScript-Code-Katas

Let's practice our JavaScript testing.
JavaScript
23
star
31

f2em.com

A Front End Engineer's Manifesto
JavaScript
22
star
32

github-issue-to-json-file

Convert a well formed GitHub Issue Form populated Markdown body into a JSON data file in the repository.
JavaScript
21
star
33

avatar-local-cache

Saves a image URL for an avatar to the local file system (and optimizes the image).
JavaScript
21
star
34

performance-sometime

Improving the web font rendering of the default Wordpress theme.
JavaScript
20
star
35

this-website-is-a-tech-talk

HTML
20
star
36

educational-sensational-inspirational-foundational

A website dedicated to a history of foundational web development blog posts.
CSS
19
star
37

pagefind-search

A web component to search with Pagefind.
JavaScript
19
star
38

webcare-webshare

JavaScript
18
star
39

artificial-chart

An SVG charting library based on D3.js
JavaScript
15
star
40

gruntlerplate

A default grunt configuration for new projects.
JavaScript
13
star
41

throbber

A loading indicator overlay for images (and maybe other things later).
JavaScript
13
star
42

ToolOrDie

A presentation on Web Developer Workflow.
HTML
12
star
43

ALARMd

Web based alarm clock
JavaScript
12
star
44

font-stats

Generates useful information about a font from a font file.
JavaScript
10
star
45

node-retrieve-globals

Execute a string of JavaScript using Node.js and return the global variable values and functions.
JavaScript
10
star
46

w3c-banners

A non-image based non-normative proposal for conformance of W3C status banners.
HTML
9
star
47

rainglow

A demo for 11tymeetup.dev
Nunjucks
9
star
48

parity-purchasing-power-price

Web Component to show Parity Purchasing Power prices.
JavaScript
9
star
49

css-tricks-font-loading

A case study of the font loading for css-tricks.com
HTML
8
star
50

iliveinomaha-banner

Retina friendly progressively enhanced banner for iliveinomaha.com
CSS
7
star
51

foitfout

A web font loading demo to showcase FOIT and FOUT behavior side by side.
JavaScript
6
star
52

async-css-loading

Test cases for asynchronous css loading
HTML
6
star
53

JsTestDriver-Boilerplate

Easy boilerplate for test driven JavaScript projects using the JsTestDriver tool.
Shell
6
star
54

Compatibility-Tests

HTML5 tests used for research for blog posts
5
star
55

BUSYNESS

This project is retired.
JavaScript
5
star
56

uniclode

Another Eleventy Serverless demo, select characters to form a Unicode Range
JavaScript
5
star
57

Raging-Netflix-Queue

RETIRED—A Google Chrome extension, provides a single click add to your Netflix queue while browsing the web.
JavaScript
5
star
58

a-single-html-file

I am a single HTML file.
HTML
4
star
59

noop

A minimal module to test importing in other tools.
JavaScript
4
star
60

a11y-tests

A series of small atomic tests used to compare accessibility linting tools.
HTML
4
star
61

eleventy-components

4
star
62

unicode-range-interchange

Do math on Unicode Ranges for web fonts.
JavaScript
4
star
63

twitter-avatar-url

Find a twitter avatar image url from a twitter username.
JavaScript
4
star
64

demo-cloudcannon-image-optimization

JavaScript
4
star
65

netlify-kasa-build-status

A little script to update my lights with the status of a Netlify build
JavaScript
3
star
66

browser-logo-icon-set

A multi-color vector icon set (grunticon generated) of browser logos
HTML
3
star
67

tweetback-zachleat

HTML
3
star
68

DOM-Sailbloat

Find the bloat in your document using this Firebug Lite plugin.
JavaScript
3
star
69

rawhyde

A boilerplate for the Jekyll/Grunt/Buttsweater combination used on zachleat.com and nebraskajs.com.
JavaScript
3
star
70

Firebug-Code-Coverage

Retired source code for an old JavaScript Code Coverage plugin for Firebug.
JavaScript
3
star
71

Snapper

JavaScript
2
star
72

demo-eleventy-base-blog

Just testing GitHub templates
HTML
2
star
73

myspacebook

It’s out of this world.
JavaScript
2
star
74

Parlour

A full screen photo gallery with flickr integration.
JavaScript
2
star
75

package-zachleat

Meta package for Zach Leatherman
JavaScript
2
star
76

eleventy-sample-css-manager

Sample created for https://twitter.com/jaffathecake/status/1153759414765203463
JavaScript
2
star
77

gif-party

JavaScript
1
star
78

edge-redirects-test

HTML
1
star
79

zachleat

I AM A ✨ SPECIAL ✨ REPOSITORY
1
star
80

space-jam

HTML
1
star
81

reverse-proxy-test

HTML
1
star