Categories: CSSScriptWeb Design

Responsive, Mobile-friendly Carousel Slider with CSS Grid – GridSlider

GridSlider is a lightweight JavaScript library that creates responsive, accessible, touch-enabled carousels using CSS Grid layout.

Table of Contents

Toggle

Features

  • Pure JavaScript implementation: No external dependencies or framework requirements.
  • CSS Grid foundation: Uses modern CSS Grid layout for responsive behavior.
  • Touch gesture support: Native swipe functionality for mobile devices.
  • Multiple slider support: Handle multiple carousels on a single page.
  • Accessibility built-in: Keyboard navigation and ARIA labels included.
  • Customizable pagination: Flexible pager styling with CSS variables.
  • Smooth scrolling: Native scroll snapping and smooth animations.
  • Responsive design: Automatically adapts to different screen sizes.

How to use it:

1. Import the GridSlider’s JavaScript and Stylesheet into your project.

<link rel="stylesheet" href="theme.css">
<script type="module">
  import initGlider from '../index.js';
</script>

2. Create the HTML structure for your carousel. You need a main container, a grid wrapper, your slide items, and a pager element as follows:

<div class="glider glider-mq">
  <div class="glider-grid">
    <div class="glider-grid-item">1</div>
    <div class="glider-grid-item">2</div>
    <div class="glider-grid-item">3</div>
    ... more slides here
  </div>
  <div class="glider-pager"></div>
</div>

3. Initialize the scarousel in your main JavaScript file. The library will automatically find and set up all elements with the default .glider class.

initGlider();

4. Override the default CSS selector for your carousel containers.

initGlider({
  sliderSelector: '.myCarousel'
});

5. Customizing the look through CSS variables.

:root {
  --glider-spacing: 1rem;
  --glider-top-padding: 0.5rem;
  --glider-right-padding: calc((100% - 80rem) / 2 + 7.75rem);
  --glider-bottom-padding: 0.5rem;
  --glider-left-padding: 0;
  --glider-peek: 0.5;
  --glider-spacing: 1rem;
}

The post Responsive, Mobile-friendly Carousel Slider with CSS Grid – GridSlider appeared first on CSS Script.

rssfeeds-admin

Share
Published by
rssfeeds-admin

Recent Posts

A Look Back, April 14

50 Years Ago The Massachusetts Public Interest Research Group (Mass-PIRG) has criticized the Northampton Small…

48 minutes ago

Westhampton rejects $500K tax override by 59 votes

WESTHAMPTON — Voters shot down a request for a $500,000 Proposition 2½ override by 59 votes…

48 minutes ago

Northampton serial arsonist Anthony Baye released 16 years after fire sprees that killed two

NORTHAMPTON — After setting 27 fires between 2007 and 2009 that terrorized Ward 3 neighborhoods…

48 minutes ago

Stovetop fire at Sugarloaf Estates apartments in Sunderland displaces residents

SUNDERLAND — Investigators have determined that the fire at the Sugarloaf Estates apartment complex on…

49 minutes ago

McGovern leads bipartisan effort to support, expand ‘food is medicine’ initiatives

Repeating the mantra that “food is medicine,” U.S. Rep. Jim McGovern is leading a bipartisan…

49 minutes ago

Leverett home destroyed in late-night blaze

LEVERETT — A two-story home just east of North Leverett center was destroyed in a…

49 minutes ago

This website uses cookies.