Giter Club home page Giter Club logo

swiffy-slider's Introduction

Swiffy Slider Logo

Swiffy Slider

Tweet

Super fast lightweight carousel and slider with touch for optimized websites running in modern browsers.
Explore Swiffy Slider docs »

See examples · Visual carousel and slider configuration

version npm version CSS gzip size CSS Brotli size JS gzip size JS Brotli size

Swiffy Slider

Super fast carousel and slider with touch for optimized websites running in modern browsers.

Modern browser offers really good options these days to create much better user experience for sliders and carousels than existing libraries offer.

This project utilizes what is available in modern browsers resulting in a super lightweight and fast slider, greatly reducing the javascript footprint and increase performance to meet todays standards.

  • Navigate with Touch, Keyboard, trackpad, pen and Mouse - because it is just browser scrolling
  • Uses native browser scroll behavior, scroll-snap and CSS grid to provide the best mobile and touch experience
  • Can run in CSS only mode - no js for even better performance
  • SEO friendly - all content is in pure markup
  • WCAG friendly - all content is in pure markup and can be annotated accordingly, supports tabbing, keyboard navigation, aria attributing and all what is needed.
  • Setup is done in pure markup and css classes, no scripting required
  • No js loading of slides, configuration or initialization
  • Vanilla javascript, less than 1.3kb ~110 lines
  • Very low overall footprint ~3.5kb in total (css+js gzip'ed)

Table of contents

Quick start

1. Add CSS and JS to website head section

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.min.js" defer>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/swiffy-slider.min.css" rel="stylesheet">

2. Add markup

<div class="swiffy-slider slider-item-helper">
    <ul class="slider-container">
        <li>Slide 1</li>
        <li>Slide 2</li>
        <li>Slide 3</li>
    </ul>

    <button type="button" class="slider-nav"></button>
    <button type="button" class="slider-nav slider-nav-next"></button>

    <div class="slider-indicators">
        <button class="active"></button>
        <button></button>
        <button></button>
    </div>
</div>

Swiffy Slider script automatically binds to all .swiffy-slider instances

Additional installation options

  • Download the latest release
  • Clone the repo: git clone https://github.com/dynamicweb/swiffy-slider.git
  • Install with npm: npm install swiffy-slider
  • Install with yarn: yarn add swiffy-slider

Loading (ESM)

// import Swiffy Slider JS
import { swiffyslider } from 'swiffy-slider'
window.swiffyslider = swiffyslider;

window.addEventListener("load", () => {
    window.swiffyslider.init();
});

// import Swiffy Slider CSS
import "swiffy-slider/css"

Read the Getting started page for examples, configuration options and a visual configurator.

Features

  • Carousel - Slide any content. Images, cards, videos, text, banners, posters, anything markup
  • Carousel - Slide using touch, keyboard, mouse or navigation buttons
  • Carousel - 1, 2, 3, 4, 5 or 6 slides visible in the slider wrapper
  • Carousel - snap to start or center slide items
  • Carousel - Slide one item or entire page on navigate when showing more than one
  • Carousel - Partially reveal next and previous (optional) slide to indicate touch scroll is available
  • Carousel - Loop to start when slides end
  • Navigation - 7 built in navigation styles for next and previous navigation in light or dark mode, 14 in total
  • Navigation - Overlay or outside navigation options
  • Navigation - Show navigation arrows on hover or always. Show on desktop, but not touch
  • Indicators - 3 built in indicator styles; pin, dots or squares in light or dark mode
  • Indicators - Overlay or outside location of indicators
  • Indicators - Navigate to slide by clicking indicator
  • Auto play - Automatically slide with specified interval
  • Auto pause - Stop playing when mouse is hovering carousel or touch is used
  • Animation - Add animations when slides slide into view
  • Animation - Choose between 6 different animations
  • Animation - Use normal, fast or slow animations
  • Scripting - Automatic or manual initialization of slider instances using swiffyslider.init or swiffyslider.initSlider
  • Scripting - Execute scripts when an item is done sliding using swiffyslider.onSlideEnd
  • Scripting - Start and stop automatic sliding using script

What's included

Within the download you'll find the following directories and files. You'll see something like this:

swiffy-slider/
├── dist/
│   ├── css/
│   │   ├── swiffy-slider.css
│   │   ├── swiffy-slider.min.css.map
│   │   ├── swiffy-slider.min.css.map
│   ├── js/
│   │   ├── swiffy-slider-extensions.js
│   │   ├── swiffy-slider-extensions.min.js
│   │   ├── swiffy-slider-extensions.min.js.map
│   │   ├── swiffy-slider.esm.js
│   │   ├── swiffy-slider.esm.min.js
│   │   ├── swiffy-slider.esm.min.js.map
│   │   ├── swiffy-slider.js
│   │   ├── swiffy-slider.min.js
│   │   ├── swiffy-slider.min.js.map
├── src/
│   ├── swiffy-slider.extensions.js
│   ├── swiffy-slider.css
│   ├── swiffy-slider.esm.js
│   ├── swiffy-slider.js

The download contains compiled and minified CSS and JS (swiffy-slider.min.*). source maps (swiffy-slider.*.map) are available for use with certain browsers' developer tools.

Bugs and feature requests

Have a bug or a feature request? Check out the issues section and see if your issue or idea is already created. If your problem or idea is not addressed yet, please open a new issue.

Documentation

Swiffy slider documentation website is part of this repo and can be found in the docs folder. Visit the doc on our github documentation page

Introduction

Swiffy slider is a wrapper defined in html with slides, navigation and indicators as its children.

All options and behavior is controlled with css classes that is added to the wrapper. No js configuration.

The wrapper is the .swiffy-slider element - options to control layout and behavior of slides, navigation and indicators are added to this element.

Markup structure

The slider markup is a .swiffy-slider wrapper that has 3 sections.

  • One .slider-container that contains the slides
  • Two .slider-nav buttons that is navigation buttons previous and next (optional)
  • One .slider-indicators that contains the indicators (optional)
<div class="swiffy-slider [slider options] [navigation options] [indicator options]" data-slider-nav-autoplay-interval="3000">
    <ul class="slider-container">
        <li>Slide 1</li>
        <li>Slide 2</li>
    </ul>

    <button type="button" class="slider-nav"></button>
    <button type="button" class="slider-nav slider-nav-next"></button>
    
    <div class="slider-indicators">
        <button class="active"></button>
        <button></button>                
    </div>    
</div>

This example uses ul>li for slides. Can also be i.e. div or other elements. This example uses button for navigation. Could also be divs, but cannot be ul>li as that would be nested. This example uses div>button for indicators but could be other elements, i.e. ul>li structure instead. Wether to use buttons or div for the navigating elements, depends on how WCAG needs to be handled.

Slider options (CSS Classes)

Options are the css classes that can be added to the .swiffy-slider element to control how the slider will look and behave. No config in JS or similar.

The example below use the .slider-item-show2 option to show 2 slides and .slider-item-reveal to reveal part of the next and previous slide. By adding additional classes behavior and layout is controlled.

Head over to the configurator to try all options

<div class="swiffy-slider slider-item-show2 slider-item-reveal">
    <ul class="slider-container">
        <li>Slide 1</li>
        <li>Slide 2</li>
        <li>Slide 3</li>
    </ul>
</div>

Slider wrapper

Change behavior and styles on slides, navigation and indicators by adding option css classes to the .swiffy-slider wrapper.

CSS class
_______________________________
Description
_______________________________
swiffy-slider The overall wrapper of the slider instance. Should be a block element. Can contain 3 different things as direct children; slider-container, slider-indicators and slider-nav

Slider sections

For possible child elements to the swiffy-slider wrapper. These sections adds slides, navigation and indicators

CSS class
_______________________________
Description
_______________________________
slider-container
  • Creates the scrollable container that holds the slides
  • Can be any element and is a CSS grid
  • Using a ul>li structure for the container and slides provides good semantics
  • The direct descendants of this element are the slides them selves and can hold any markup
  • The width of the slides are controlled by the slider options. Default is 100% width
  • Can be styled using slider-item-* options
slider-nav
slider-nav-next
  • Creates a navigation button
  • Should be button element and there should be exactly 2
  • Default is a left button
  • Add slider-nav-next to make the next button
  • Can be styled using slider-nav-* options
slider-indicators
  • Creates a container for indicator buttons
  • The direct descendants of this element are the indicators. Add active for the active indicator for first load
  • Descendants should be button elements and there should be one button per slide or per page when showing more than one slide
  • Can be styled using slider-indicators-* options

Slider options

For the swiffy-slider wrapper. The slider-item-* option classes affects the slides (The slider-container children)

CSS class
_______________________________
Description
_______________________________
slider-item-show2
slider-item-show3
slider-item-show4
slider-item-show5
slider-item-show6
Shows 2, 3, 4, 5 or 6 slides at a time in the slider wrapper. Each slide is either 1/2, 1/3, 1/4, 1/5 or 1/6 of the slider wrapper width.
slider-item-show2-sm Shows 2 slides at a time in the slider wrapper when in small viewport. By default show2-5 will show only one slide when in viewports less than 62rem (992px in most cases). With this option it shows 2 in small viewports
slider-item-reveal Reveals some of previous and next slide. Each slide is either 1/1, 1/2, 1/3, 1/4 or 1/6 of the slider wrapper width minus a little to reveal next and previous slides
slider-item-ratio Enables ratio sizing of the slide elements. Default ratio is 2:1 or 50% meaning the slides have half the heigh of their width. This option sets object-fit:cover; on first element inside the slide element - to stretch images to fill out the slide box and keep aspect ratio.
slider-item-ratio-32x9
slider-item-ratio-21x9
slider-item-ratio-2x1
slider-item-ratio-16x9
slider-item-ratio-4x3
slider-item-ratio-1x1
slider-item-ratio-3x4
Controls the slide ratio when ratio is enabled. Default ratio is 2:1 or 50% meaning the slides have half the heigh of their widt.
slider-item-ratio-contain Sets the content of a ratio enabled slide to have object-fit:contain; instead of default object-fit:cover;. This ensures that if the content of the slide is an image or embedded video, it is scaled down so all is visible within the slide box.
slider-item-nogap Removes the horisontal gap between slides
slider-item-snapstart Snaps slides to start of the slider wrapper instead of center when using .slider-item-reveal
slider-item-nosnap Removes auto snapping for slides so they slide freely. Primarily have an affect on touch devices as navigating with arrows and indicators is per slide or per page
slider-item-nosnap-touch Same effect as slider-item-nosnap but only on devices that has a primary input which is not a mouse, i.e. mobile media (hover: none)
slider-item-first-visible Use with .slider-nav-autohide to hide the previous navigation arrow when the slider loads. Will automatically be removed or added when first slide is not or is visible
slider-item-last-visible Use with .slider-nav-autohide to hide the next navigation arrow when the slider loads. Will automatically be removed or added when last slide is not or is visible
slider-item-helper For debugging: Adds a test layout to slide items; minimum height, background color, centers content and background. Meant for testing and should be removed in real code

Navigation options

For the swiffy-slider wrapper. The slider-nav-* option classes affects the slider-nav elements

CSS class
_______________________________
Description
_______________________________
slider-nav-page Slides entire page when showing more than one slide item on the slider wrapper. Default behavior moves just one slide to the left or right
slider-nav-noloop Disables slider loop - so when on first/last slide navigate previous/next does not take the user to the last/first slide
slider-nav-nodelay Disables smooth scrolling when sliding using navigation buttons, indicators and autoplay. Makes the new slide or page appear instantly with no scroll smoothing. Does not affect touch navigation
slider-nav-autoplay Automatically slide to next slide or next page in intervals. Default is 2500 ms = 2.5s
data-slider-nav-autoplay-interval attribute Changes the default autoplay interval - value is in ms. data-slider-nav-autoplay-interval="3000". Default value is 2500, minimum value is 750 ms
slider-nav-autopause Stops and restarts the autoplay when mouse is hovering the slider wrapper or when it is touched on touch devices. Will restart on mouseout, but not when touch ends
slider-nav-round Changes the default navigation arrows to a circle with arrow. Default color is white with black arrow
slider-nav-touch Shows navigation buttons on touch devices. By default navigation buttons are hidden on touch devices using the media (hover: none) query. By adding this option, the navigation buttons are always visible on touch devices
slider-nav-visible Makes the nav buttons visible always. By default navigation buttons are hidden until the slider wrapper is hovered
slider-nav-outside Moves the navigation buttons outside the slider wrapper and shrinks the width of the slider wrapper accordingly (by 3 or 5 rem on each side depending on navigation style)
slider-nav-outside-expand Moves the navigation buttons outside the slider wrapper by applying negative margins (-3 or -5 rem) so the slides and wrapper keeps their size. The navigation buttons overlays surrounding content.
slider-nav-scrollbar Makes the scrollbar for the .slider-container visible. Acts as indicator and navigation if running in css only mode. On touch devices the scrollbar is not shown when not sliding because that is how the browser behaves
slider-nav-dark Changes the navigation buttons to a dark version. Black arrows or black circle with white arrows
slider-nav-autohide Will hide appropiate navigation arrow when the first or last slide is visible to indicate that sliding is at its start or end. On load the arrow will first disappear when the script is loaded. Also add `.slider-item-first-visible` class to the `.swiffy-slider` instance together with `.slider-nav-autohide` to hide the start arrow on load before js executes.

Indicator options

For the swiffy-slider wrapper. The slider-indicators-* option classes affects the slider-indicators child elements

CSS class
_______________________________
Description
_______________________________
slider-indicators-round Changes the default indicators to a circle
slider-indicators-square Changes the default indicators to a square
slider-indicators-outside Moves the indicator buttons under the slider wrapper and increases the height of the slider wrapper but not the slides them selves
slider-indicators-dark Changes the indicator buttons to a dark version
slider-indicators-highlight Hightlights the active indicator even more by increasing its size
slider-indicators-sm Shows indicator buttons on small devices under 992px in width. By default indicator buttons are hidden on small devices. By adding this option, the indicators buttons are always visible. Since the number of indicators and number of slides does not match on small devices when showing more than one item per page, do not use this option in that case

Animation options

For the swiffy-slider wrapper. The slider-nav-animation-* option classes affects the animation of slides when they slide into view.

CSS class
_______________________________
Description
_______________________________
slider-nav-animation Enables animation on slides. An animation effect class is also required for animation to be enabled
slider-nav-animation-appear Apear animation using opacity and scale - starting from 30% opacity and a 90% scale
slider-nav-animation-fadein Fade in animation using opacity - starting from 50% opacity. Can be combined with .slider-nav-animation-scale/scaleup
slider-nav-animation-scale Scale up animation using scale - starts with 90% size. Can be combined with .slider-nav-animation-fadein
slider-nav-animation-scaleup Scale up animation using scale - starts with 25% size. Can be combined with .slider-nav-animation-fadein
slider-nav-animation-turn Turn animation using rotateY - starts with 70deg ratotation
slider-nav-animation-slideup Slide up animation using translateY - starts at 60% of the height
data-slider-nav-animation-threshold attribute Changes the default animation threshold - value is between 0-1. data-slider-nav-animation-threshold="0.3". Default value is 0.3. This setting defines how many percent of a slide should be visible before the animation starts

Javascript

The Swiffy Slider script can be accessed using window.swiffyslider or simply swiffyslider

All options and behavior is handled by the css classes, so using the scripts directly is only for more advanced scenarios.

Method
_______________________________
Description
_______________________________
swiffyslider.version; Needs no explanation :-)
swiffyslider.init(rootElement = document.body); Initializes all instances of .swiffy-slider elements and binds events to handle navigation, indicators and autoplay. By default document.body is searched for instances, but can be limited further to i.e. content area (and skip header, navigation, footer etc) to further improve init performance.
swiffyslider.initSlider(sliderElement); Initializes one instance of swiffy slider wrapper. The passed element has to be a .swiffy-slider element
swiffyslider.slide(sliderElement, next = true); Slides to the next slide or next page depending on the nav settings. The passed slider element has to be a .swiffy-slider element. By default this method slides next, but call it with false to slide to previous
swiffyslider.slideToByIndicator(); This method is called when an indicator button is clicked. Should not be called directly. Instead call slideTo
swiffyslider.slideTo(sliderElement, slideIndex); Slides to the specified slide (index starts with 0 for first slide). The passed slider element has to be a .swiffy-slider element.
swiffyslider.onSlideEnd(sliderElement, delegate, timeout = 125); Provide a callback/delegate function to get called when sliding ends. The default timeout is 125ms and should not be too low as it could cause the delegate to be called more than once on each scroll. The passed slider element has to be a .swiffy-slider element.
swiffyslider.autoPlay(sliderElement, timeout, autopause); Manually starts autoplay for a container using the specified timeout. Autopause can be enabled. Usually auto play is handled using css option classes. This method can be used to start autoplay when the slider scrolls into view or similar. The passed slider element has to be a .swiffy-slider element.
swiffyslider.handleIndicators(sliderElement); Manually updates the indicators active state to reflect the current position of the slider. The passed slider element has to be a .swiffy-slider element.

Listening for sliding ends for a container

<script>
const sliderElement = document.getElementById('myslider');
swiffyslider.onSlideEnd(sliderElement, function() {
    console.log('Scrolling stopped');
});
</script>

Listening for sliding ends for a container and find visible slides

<script>
window.addEventListener(&#39;load&#39;, () =&gt; {
    const sliderElement = document.getElementById(&#39;myslider&#39;);
    swiffyslider.onSlideEnd(sliderElement, function() {
        const visibleSlideElements = getVisibleSlides(sliderElement);
        const visible = [];
        for (const slide of visibleSlideElements) {
            visible.push(slide.innerText);
        }
        console.log(visible);
        console.log(visibleSlideElements);
    });
});

function getVisibleSlides(sliderElement) {
    const container = sliderElement.querySelector('.slider-container');
    //returns an array of slide elements that are fully or partially visible
    const visibleSlides = [];
    //We are using a grid layout and the slides left and right properties include the width of the gap, so when comparing with container width add a gap for each side of the slide gap.
    const gapWidth = parseInt(window.getComputedStyle(container).columnGap);
    for (const slide of container.children) {
        var slideScrollLeftPosition = slide.getBoundingClientRect().left - container.getBoundingClientRect().left;
        var slideScrollRightPosition = slideScrollLeftPosition + slide.offsetWidth - gapWidth;
        if (slideScrollLeftPosition &gt;= 0 &amp;&amp; slideScrollRightPosition &lt;= container.offsetWidth) {
            visibleSlides.push(slide);
        }
    }
    return visibleSlides;
}
</script>

Javascript loading and binding

Load Swiffy slider using webpack, ESBuild and other build tools. In your index.js (or whatever you call it). NOTE: Swiffy slider is an ES Module and you need a supported processing ECMAScript compiler - i.e. webpack 5+ etc.

// import Swiffy Slider JS
import { swiffyslider } from 'swiffy-slider'
window.swiffyslider = swiffyslider;

window.addEventListener("load", () => {
    window.swiffyslider.init();
});

// import Swiffy Slider CSS
import "swiffy-slider/css"
// import Swiffy Slider src CSS unminified
import "swiffy-slider/src/swiffy-slider.css"

Avoid autobinding by adding data-noinit attribute on the script tag and then attach the slider manually

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.min.js" data-noinit defer>
<script>
    window.addEventListener('load', () => {
        //Use only one of the loading options below!
        //loads all sliders
        swiffyslider.init();
        //loads specific slider
        swiffyslider.initSlider(document.getElementById('myslider'));
    });
</script>
<div class="swiffy-slider" id="myslider">
  <div class="slider-container">
    <div></div>
  </div>
  ...
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.min.js" data-noinit defer>
<script>
    window.addEventListener('load', () => {
        //loads all sliders in main and skip header and footer search for increased init performance.
        swiffyslider.init(document.getElementById('content'));
    });
</script>
<header>...</header>
<main id="content">
  <div class="swiffy-slider" id="myslider">
    <div class="slider-container">
      <div></div>
    </div>
    ...
  </div>
</main>
<footer>...</footer>

Load as module using ES version of the script

<script type="module">
    import {swiffyslider} from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.esm.min.js'; 
    window.swiffyslider = swiffyslider; 
    window.swiffyslider.init(); 
</script>

Load as ES module on demand, here using load - could be when slider scrolls into view or navigation arrow is clicked the first time. Load module and initialize sliders.

<script>
window.addEventListener("load", () => {
    import ('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.esm.min.js').then((swiffysliderModule) => {
        swiffysliderModule.swiffyslider.init();
    });
});
</script>

Load as ES module on demand. Load module and assign to window for later script manipulation of slides

<script>
window.addEventListener("load", () => {
    import ('https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.esm.min.js').then((swiffysliderModule) => {
        window.swiffyslider = swiffysliderModule.swiffyslider;
        window.swiffyslider.init();
    });
});
</script>

Optimized loading

When loading the script with defer attribute, the initialization will happen as soon as the script is downloaded. Deferred scripts are requested and run as soon as the document is parsed by the browser. This is the recommended approach.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.min.js" defer>

If the script is loaded without defer attribute, the initialization will happen when document.readyState === 'interactive' using a document.onreadystatechange event listener. The script will load and run before the Dom is loaded, but has been parsed.

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/swiffy-slider.min.js">

The above approach ensures the sliders are initialized as soon as possible and earlier in the page life cycle compared to using load or DOMContentLoaded events. This might not always be optimal depending on what else is running on the page. Since the content of Swiffy Slider is always markup and is rendered when the markup is parsed and does not change when initialized, a later loading of the script and initialization of the sliders could be a benefit to leave more power for more important scripts. See "Load as ES module on demand".

CSS variables

The Swiffy Slider CSS is making use of a number of CSS variables that can be overriden to control behavior and styling

Slide sizes, ratios, navigation etc. can be controlled by overruling the variable on the .swiffy-slider instance or in custom css.

Variable Example Description
--swiffy-slider-item-width --swiffy-slider-item-width:75%; Calculated based on the number of slides shown, the gap, reveal etc. Should not be overriden. INFO If needed, it has to be overriden on the .slider-container element.
--swiffy-slider-item-gap --swiffy-slider-item-gap:25px; Changes the gap between slides when enabled. Default --swiffy-slider-item-gap is 1rem, but can be any valid CSS mesurement. The --swiffy-slider-item-gap is part of the calculation of --swiffy-slider-item-width
--swiffy-slider-item-reveal --swiffy-slider-item-reveal:20%; Changes the width of the reveal of next and previous slides when enabled. Default --swiffy-slider-item-reveal is 8rem if previous and next is revealed and 4rem if only next is revealed (if .slider-item-snapstart is in use). The --swiffy-slider-item-reveal is part of the calculation of --swiffy-slider-item-width
--swiffy-slider-item-ratio --swiffy-slider-item-ratio:100/33.3 Sets the ratio to a custom value. Use with .slider-item-ratio and omit use of any .slider-item-ratio-* classes
--swiffy-slider-item-count --swiffy-slider-item-count:8; Sets the number of slides to show - same as using .slider-item-show{n} but can i.e. be set to a number higher than 6 if needed.
--swiffy-slider-nav-light --swiffy-slider-nav-light:lightcyan; Sets the light color for navigation arrows. Default is #fff. Use to control the color of light navigation. Square and Round navigation use both colors - one for backgrond, the other for arrow color.
--swiffy-slider-nav-dark --swiffy-slider-nav-dark:darkolivegreen; Sets the dark color for navigation arrows. Default is #333. Use to control the color of dark navigation. Square and Round navigation use both colors - one for backgrond, the other for arrow color. Can be any color variable.
--swiffy-slider-nav-zoom --swiffy-slider-nav-zoom:1.25; Use to overrule the navigation arrow sizes. Default is 1 for normal sizes and .75 for small sized navigation. Set to i.e. 1.25 to make navigation arrows larger.
--swiffy-slider-track-opacity --swiffy-slider-track-opacity:0.25; Sets the scrollbar track opacity when scrollbar is displayed
--swiffy-slider-track-height --swiffy-slider-track-height:1rem; Sets the scrollbar track height. Default is .5rem if scrollbar (.slider-nav-scrollbar) is enabled.
--swiffy-slider-animation-duration --swiffy-slider-animation-duration:0.75s Sets the animation duration. Default is 0.75s. Using .swiffy-slider-animation-fast sets the duration to .25s. Using .swiffy-slider-animation-slow sets the duration to 1.25s
--swiffy-slider-animation-delay --swiffy-slider-animation-delay:0.5s; Sets the delay before animation begins when a new slide scrolls into view. Default is 0s (no delay).
--swiffy-slider-animation-timing --swiffy-slider-animation-timing:ease-in-out; Sets the animation timing method, default is ease-in-out.

Example

<div class="swiffy-slider slider-item-reveal slider-item-ratio slider-nav-round slider-nav-visible" 
style="
--swiffy-slider-item-ratio:100/33.3;
--swiffy-slider-nav-light:lightcyan;
--swiffy-slider-nav-dark:darkolivegreen;
--swiffy-slider-nav-zoom:.85;
--swiffy-slider-item-reveal:25%;">

    <ul class="slider-container">
        <li>...</li>
    </ul>

    <button type="button" class="slider-nav"></button>
    <button type="button" class="slider-nav slider-nav-next"></button>

    <div class="slider-indicators">
        <button class="active"></button>
        <button></button>
        <button></button>
    </div>
</div>

Safari smooth scrolling polyfill

UPDATE: Safari 15.4 introduces smooth scrolling: See release notes Sliding the carousel on touch devices using fingers are not affected by this issue.

When sliding using buttons, indicators and javascript, the new slides are shown instantly with no smoothing when using Safari.

In Safari based browsers, smooth scrolling is not supported because it is still lacking browser support. See Can I use

If you want to support smoooth scrolling on Safari based browsers, add this polyfill to your head section

<script src="https://unpkg.com/smoothscroll-polyfill/dist/smoothscroll.min.js"></script>

Limitations

These limitations are known and intentionally there to keep this library small, fast and smooth.

  • Scroll speed comes in 2 flavors - instant or 'smooth'. This is because that is what browsers support out of the box using CSS scroll-behavior. See MDN
  • Does not support slides of uneven widths. The width is controlled by the width of the wrapper and can have 1-6 slides per page depending on configuration.
  • Smooth scrolling is not supported out of the box in Safari (Before v 15.4) (iOS + Mac) but can be fixed using a polyfill. See polyfill
  • RTL is untested but as the entire slider is just markup, it should be supported very well
  • Works in 'modern' browsers from the last ~3 years only. No IE support or anything funny.

Use other sliders and carousels if these limitations is important in your project.

Contributing

You are more than welcome to contribute by opening issues and create pull requests. Keep in mind that this project is meant to be very simple in nature and support recent browsers only.

This project is not going into a race of adding as many features as possible - but quite the opposite. Performance and filesize has high priority.

The general rule is, that Swiffy Slider is covering the most common usages, and that more exotic usages are made in examples. If not at least 50% of all installations need a feature, the feature probably belong somewhere else.

Examples of more exotic use cases are more than welcome as part of the examples, so please create pulls for that.

Open tasks that you could help with:

  • Svelte component
  • Vue component
  • React component

Thank you for your understanding.

Star gazers

Feel free to star this project and help spread the word.

Stargazers repo roster for @dynamicweb/swiffy-slider

Examples of sites using Swiffy Slider

Send an email to https://github.com/nicped if you would like your site on this list.

Versioning

See the Releases section of our GitHub project for changelogs for each release version of Swiffy Slider.

Creators

Nicolai Høeg Pedersen

Dynamicweb

Copyright and license

Code and documentation copyright 2022 the Swiffy Slider Authors and Dynamicweb A/S Code released under the MIT License. Docs released under Creative Commons.

swiffy-slider's People

Contributors

aimeos avatar arrow2nd avatar dwstj avatar nicped avatar onthegocode avatar shubrautt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiffy-slider's Issues

Safari issue with slider buttons on full screen

Describe the bug
Slider buttons not working on Safari iOS, iPadOS, MacOS,... on fullscreen module.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://swiffyslider.com/examples/
  2. Click on the image to open the fullscreen module.
  3. Try to click the buttons to go to the next or previous.
  4. No response

**Desktop **

  • OS: MacOS 12.3.1
  • Browser Safari
  • Version 15.4

Smartphone

  • Device: Iphone 12 Pro
  • OS: iOS 15.4.1
  • Browser: Safari
  • Version: 15.4

Additional information
When disabling the CSSOM View Smooth Scrolling, the buttons work again.
Safari>Develop>Experimental features>CSSOM View Smooth Scrolling.

Tried adding the package for smooth scroll polypill, but that doesn't seem to help.

npm package esm sass css import

In my JS I import like this which works: import {swiffyslider} from 'swiffy-slider';
In my scss this doesn't work: @import "~swiffy-slider/dist/css/swiffy-slider.min.css";

Am I doing something wrong? Or does your package need to additionally export the css for NPM, Laravel Mix 6, ES6? Currently you have "exports": "./src/swiffy-slider.esm.js", which works for the js only for me.

Autoplay don't work on mobile

Describe the bug
The slider work fine on desktop and on the adaptative view on desktop, but on my mobile the autoplay don't work, i see only the first image. (scroll works)

Smartphone (please complete the following information):

  • Device: S20fe and iPhone XR
  • OS: iOS 16, android 13
  • Browser: Safari, chrome and firefox

Additional context
www.eliot.fr

Best way to initialize/de-initialize Swiffy on resize event?

First off, thank you for building such a fantastic slider/carousel! I have a unique project the layout for which requires a slider to initialize on card-style elements only for smaller viewports, and I'm wondering if you have a recommended method for initializing/de-initializing Swiffy via a resize event, say, with window.matchMedia or some other method? Thanks for any suggestions here!

Remove "template" tag from children of .slider-container and .slider-indicators making library compatible with AlpineJS

Is your feature request related to a problem? Please describe.
I want the library to be compatible with AlpineJs and the Web HTML Element "template". AlpineJS use the "template" element for every actions, loop etc... and SwiffySlider take alld child element to display indicators and slide.
See AlpineJS Templating usage : https://alpinejs.dev/essentials/templating#looping-elements

Describe the solution you'd like
I already implemented the solution (PR in preparation) it simply consist in excluding the "template" from the children and let all other tags as is

PR #47

Issues with slider loop

Swiffy slider jumps to start or end when loop is activated.
Slides do not actually loop. They just jump.

Add an infinite loop option

I was going to use this lib in my project, but I had to refuse when I realized that there was no infinite loop option.

NPM/Yarn import not working with React

Describe the bug
When attempting to import swiffyslider into a React project, I get Module not found: Can't resolve 'swiffy-slider'.

To Reproduce
Steps to reproduce the behavior:

  1. Run yarn add swiffy-slider in fresh project.
  2. Create index.js with import swiffyslider from 'swiffy-slider
  3. Run node index.js

Expected behavior
The swiffyslider object is imported into the file, and I can use it.

Additional context
In attempting to debug this issue, I think part of it has to do with the package.json (it has "main": "dist/swiffy-slider.ESM.min.js" when I think it should be "main": "dist/js/swiffy-slider-ESM.min.js"). I think there might be an issue with ES6 Module Syntax vs CommonJS syntax.

No loop in Chromium with zoom/scaling

The loop stops working when the browser is zoomed out or in (and with some zoom levels it still loops) or when OS is set up to interface scaling. Maybe it has something to do with grid-auto-columns.

Applies to at least Chrome, Edge.

cannot import css from sass

I can import the css from ES6 but when from sass .scss file I get this error when I npm run dev:
Error: Package path ./src/swiffy-slider.css is not exported from package

Destory method missing

Describe the bug
We are planing to use this slider on our SPA, but therefore we need a destroy() method, that is taking care of clean up and unbinding from all the event. Are you planing to implement that?

Differents height for images

Is your feature request related to a problem? Please describe.
For a web application, we let users upload images, but we end up with images of different sizes

Describe the solution you'd like
It is possible to have a height that changes according to the size of the images rather than the size of the images ?

Additional context
At the end of this slider, there is an example of Autoheight

I like your slider, very easy to use :)

Fullscreen carousel with image description

I'm trying to use the fullscreen swiffy-slider with image descriptions. I used your example as a starting point but I need to use a bootstrap 5 card inside the li element so it shows the image description below the image:

<li class="h-100" tabindex="-1">
<div class="card">
  <img src="../assets/img/photos/img2.webp" class="h-100 w-100 card-img-top" style="object-fit: cover;" loading="lazy" data-bs-dismiss="modal" alt="...">
  <div class="card-body">
    <p class="card-text">This is the image description...</p>
  </div>
</div>
</li>

My images are different in size and orientation (landscape/portrait) but I want them to be displayed in the original height/weight (max height/weight if possible but not exceeding the viewport) together with the image description.

How can I do this without getting a scrollbar and content outside of the viewport?

Question about "beforeSlide" event

Hello,
Is there any way to hook in before slide changes, like a beforeSlide() event. Checked the readme. Did I miss something?

I'm looking for a way to stop a video playing before it plays on somewhere in Background.

Playing next slide when video in slider is ended

Hello!
I like this slider. I managed to use it in my project but wanted to automatically play next slide only when video is ended or paused, but I couldn't figure out how to achieve this.
I am asking: how can this be done?
Thank you!

Two clicks to jump from the last slide to the first when "Mouse draggable" is active

Hi,

when "Mouse draggable" is set, the last slide switches to the first slide after repeated mouse click only. The first click on the right arrow makes the slide twitch a bit, and it switches only after the second click.

Tested on the latest FF, Chrome, and Chrome Canary.

You can check it on the first example from the Configurator with these settings.

Unfortunately, it isn't reproduced all the time on the configurator page, but I have this issue 100% of the time on my test page. I can email it to you if that's ok.

npm esm old version works, new version doesn't + bogus documentation

package.json:

    "dependencies": {
        ...
        "swiffy-slider": "^1.2.0"
    }

bootstrap.js:

import {swiffyslider} from 'swiffy-slider/dist/js/swiffy-slider.ESM.min.js';
window.swiffyslider = swiffyslider;
window.swiffyslider.init();

app.scss:
@import "~swiffy-slider/dist/css/swiffy-slider.min.css";

When I tried to upgrade from v1.2 to 1.4 the includes are no longer found when I npm run dev. I realized that the JS min was renamed to lowercase swiffy-slider.esm.min.js and I made the change but the assets are still not able to be loaded successfully the same way they were in the older version.

Is there anything really obvious I'm missing here?

I saw in a previous ticket from January that the asssets for a period of time were not included in the npm package? Why was the documentation changed to only show CDN examples? Could you please test this NPM/Laravel/Webpack implementation and then document it for other people that use ESM but do not want to have additional includes to a CDN?

Even the documentation on npmjs.com for ESM shows examples pointing to a specific version of Swiffy on CDN. Doesn't this ENTIRELY defeat the point of using NPM? Please correct your examples to something like mine if you can get it working with the new version.

Support for vertical slider

The current implementation is great for horizontal sliders.
Are there any plans to support vertical sliders too?

Slider carousel nowrap or rewind behavior

I have a page topper slider on autoplay, but the rewind effect when the slider starts over is distracting as it slides left though all the slides already seen.

Is there a way to make the slides wrap, so after the last slide, it continues to auto play to the right, more like a carousel?

Here's a quick clip showing the default slider behavior I see now with two test slides: https://www.dropbox.com/s/juab27hic4ablyq/swiffy-slider-carousel-question.mp4?dl=0

If "Mouse draggable" is set, swiping on mobile does not work

Currently if "Mouse draggable" is set, it is not possible on mobile phones to drag the slider. I think is a problem and UX could be improved

Describe the solution you'd like
For a better/expected UX it should still be possible to swipe on smartphones even if the setting "Mouse draggable" is set.

Thank you!

Random Scrollposition

Describe the bug
The position of the scrollbar is random and changes upon refresh.

To Reproduce

  1. Go to https://lautstark-jrk.de/
  2. Scroll down to sliders
  3. Check scroll positions
  4. Refresh to see changing random position

Expected behavior
With class slider-item-snapstart the scrollposition should be start, not a random position.

Screenshots
screenshot-lautstark-jrk de-2022 10 11-09_37_12

swiffy-scrollposition-bug.mp4

Desktop

  • OS: Windows
  • Browser: Chrome
  • Version 106.0.5249.103

Problem seems not to occur on the following setups
IOS Safari & Chrome
Windows Firefox

Issue with extension file

The extension files shows some error. I have used it a few days ago it worked fine but is showing up this error from 2 days.

Uncaught TypeError: Cannot set properties of undefined (setting 'extensions')
at

Moreover, the mouse dragging feature is also not working. I have tried taking the script running on you website which shows no errors but it does not seem to work.

Move by more than one slide?

Hello,
clicking on the prev/next buttons makes the slider move by one slide, even if there are more than one slide displayed next to each other (slider-item-show5).

is it possible/can it be made possible to set the number of slides the slider moves?
Something like "slider-item-move5"?

That would make Swiffy Slider even a bit more awesome than it already is.

Best
Per

P.S. The top right "Download" button on swiffyslider.com leads nowhere.

Slider-nav-round Next and Previous icons alignment issue at mobile sizes

Describe the bug
When the slider-nav-round icons are used, and the browser view is reduced to a mobile size, the background circles are now smaller than the svg icons and don't align perfectly.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the examples page https://swiffyslider.com/examples/
  2. Reduce the browser view to a mobile size (less than 990px wide)
  3. Scroll down to the "Articles" example carousel (4th carousel on the examples page)
  4. See the next and previous nav icons.

Expected behavior
Icons expected to be centered in their background circle. Perhaps the background circle should not be reduced in size on mobile view. Or perhaps the svg icons should also be reduced in size to fit within the circles?

Screenshots
image

Desktop:

  • OS: Windows 10
  • Browser Chrome 99, Firefox 98, Vivaldi 5.1.2567.66, Edge 99.0.1150.46

Smartphone:

  • Device: iPhone 11 Pro iOS 14.6 Safari 14 (emulated via Firefox Dev Tools)

Bare bones version?

Is there the possibility to make a "bare bones" version of Swiffy Slider? Or does that not fit into the concept?

I have replaced a couple of old sliders on clients' websites with Swiffy Slider, and for the new slider to fit into the whole design, I had to override quite a bit of the CSS.

I do love the possibility to style the slider just by adding classes, and I am not overly bothered by loading CSS I don't end up using. But it would be great to have a .pure class (or something) that does not style the elements, so I only have to add, not to override.

As I have said before – your slider is a dream come true when I had already given up on looking for something usable and also on trying to write my own. Many, many thanks for this great piece of software – and no less for the stellar support!

Freely touch navigation + Ratios

First, congrats on your work, I am trying to know after reading the docs and see the Easy configuration of Swiffy Slider if:

1.- Is there any way to leave the users move the slides freely, I mean that when I try to move 2, for example it does not move 2 it goes 1 by 1. I tried "slider-item-nosnap" but it does not work.

2.- Is there any way to change the ratios (slider-item-ratio) according to the screens? I am working with Bulma and should I include the ratio css classes to the breakpoints? Would swiffy work?. That way in a mobile screen the ratio would be a different one from a dektop for example.

Thank you and all the best, congrats again for your work.

automatic and responsive indicators

Is your feature request related to a problem? Please describe.
could not find any solution where indicators are automatically and responsively generated according number of slides

Describe the solution you'd like
calculate number of "pages" and insert the same amount of indicators to DOM accordingly

Describe alternatives you've considered
none :)

Additional context
currently it's hardcoded and thus not responsive

Navigation is visible on touch device (phone)

When "slider-nav-visible" option is set and "slider-nav-touch" is not set, navigation arrows are still visible for me on my phone. They shouldn't be, right?

Android 11, FF, Chrome.

изображение

Hide left arrow on load

I'm being nit-picky, but when I enable arrows, I'm seeing one on the left on initial load. It doesn't do anything, and I don't want it to. Wondering if it could just be hidden until the user clicks right one time.

Is this something I should implement on my end?

image

Responsiveness for tablet(medium devices)

Swiffy slider is a great library ! No flaws loved the configuration feature provided which eases the development. Just no words for how smoothly it works on mobile. But I found one issue that is there is not option to show less number of slides on tablet devices. I am showing news cards as 5 in desktop and 1 in mobile want to show 3 of them in tablet/Ipad devices but found no option for that. So if possibe please add a feature to customise the number of slides shown on tablet/IPad.

Standard Sass and CSS import doesn't seem to be working?

Hi, I couldn't find documentation on how to import the CSS files outside of JS. I see there's another similar issue over here: #24 (I'm currently using version 1.5.1, which should have fixed that).

Currently, doing @import "swiffy-slider"; or @import swiffy-slider/dist/css/swiffy-slider; causes a whole lot of problems with Vite.js (which uses esbuild under the hood). For instance:

Error: Missing "./dist/css/swiffy-slider" export in "swiffy-slider" package
Error: Failed to resolve entry for package "swiffy-slider". 
The package may have incorrect main/module/exports specified in its package.json: 
Failed to resolve entry for package "swiffy-slider"

PS.: This might not have anything to do with it, but after looking at other packages, I notice that style and exports don't usually start with ./.

Multiple Sliders on One page

Hi!

Thank you for Swiffy slider - it's super easy to implement and understand.
I wanted to ask if it's possible to somehow add few sliders on the same page without them having same style/layout ?
I have tried few times, but it seems that as the classes are the same, any new slider on the page "takes up" the first one's formatting.

Option to add custom breakpoints

So I was working on a clients projects and being an e-commerce site it had several products to display. Reading through the docs the current behavior for example defaults from 6-4-2.

I'd prefer if I could choose my own breakpoints since some images/containers don't look how I want them to, e.g it looks too big for that specific break-point

I'm currently using Swiper JS as that's the one being used on the clients site at the moment, an alternative I've looked at is Glide and Splide JS

undefined is not an object

Describe the bug
We use error tracking software on our website and an event that is popping up regualrly relates to

'undefined is not an object'
f(t&&Object.prototype.hasOwnProperty.call(t,"addEventListener")){T(t,"addEventListener",function(o){var i={component:"".concat(e,".prototype

Crashed in non-app: ./node_modules/swiffy-slider/src/swiffy-slider.esm.js in handleIndicators

To Reproduce
unfortunatly we cannot provide steps to reproduce due to it been an intermittent issue.

Expected behavior
expected it not to occur?

Screenshots
N/A

Desktop (please complete the following information):

  • Majority on Safari v15+
  • Mac (18%)

Smartphone (please complete the following information):

  • Safari Mobile 15.5 and 15.6 (57%)
  • Iphone (74%)

Additional context
Our application is on NEXTJS.

and example of how swiffy is rendered in a component.

import React, { useState, useEffect, useRef } from 'react';
import Link from 'next/link';
import Container from '../../Container';
import Image from 'next/image';
import Headings from '../../heading/Heading';
import { swiffyslider } from 'swiffy-slider';

function Classic({ data, title, cta }) {
  const { _metadata, content } = data.classic;

  const sliderRef = useRef()

  let dotsClass = 'desktop:hidden bg-dark'

  useEffect(() => {
    swiffyslider.initSlider(sliderRef.current)
  }, [])

  return (
    <section id={_metadata.uid} className="content-list bg-dawn-grey-10 standard-padding">
      <Container fullPage={false}>
        <Headings headingContent={title} headingClassName='h4 md:h2 text-center mx-12 mb-10' />
        <div className="block md:flex flex-row flex-wrap w-full justify-between mx-auto">
          <div className={`content-list-slider swiffy-slider slider-nav-autoplay slider-nav-visible slider-indicators-sm`} data-slider-nav-autoplay-interval={3000} ref={sliderRef}>
            <ul className="slider-container" tabIndex={0}>
              {content.map((item, index) => {

                return (
                  <li className="flex-1 px-4 mb-2.5" key={index}>
                    <div className="relative">
                      <Image
                        src={`${item.image.url}?disable=upscale`}
                        width={274}
                        height={204}
                        objectFit={"cover"}
                        layout={"responsive"}
                        alt={item.image.title.replace(/\.[^/.]+$/, "")}
                      />
                    </div>
                    {item.overlay_content.show_overlay == true && item.overlay_content.show_icon == true ? <OverlayIcon icon={item.overlay_content.icon} /> : ""}
                    {item.overlay_content.show_overlay == true && item.overlay_content.show_icon == false ? <OverlayText text={item.overlay_content.text} /> : ""}

                    <h3 className="sh10 md:sh9 text-center mb-2">{item.title}</h3>
                    <p className="text-center max-w-sm mx-auto body-r">{item.description}</p>
                  </li>
                )
              })}
            </ul>

            <div className={`slider-indicators slider-indicators-round z-30`}>
              {content.map((item, index) => {
                return (
                  // set first indicator to 'active'
                  <button key={`slider-indicator-${index}`} className={`${index === 0 ? 'active' : ''} ${dotsClass} slider-indicator`}>
                    <span className="sr-only">Slide {index}</span>
                  </button>
                )
              })}
            </div>
          </div>
        </div>
        <CallToAction show={cta.show_cta} data={cta} />
      </Container>
    </section>
  )
}```

better fade effect

Instead of fading to a color between slides during fade, would there be a way to fade one slide into another. I wonder if it could be a brief overlap then opacity goes to 0 for the exiting slide? Here are a few examples (but it is hard to see in the screen recording)...

This was an old slider with a nice fade opacity effect...

opacity.fade.mov

This is the same slider with the swiffy fade using a light gray in between...

swiffy.fade.mov

Readme has outdated link

On the bottom of the readme.md file there is a link to Dynamicweb Swift Ecommerce Starter
This link leads to dead end and also the domain dynamicweb-cms.com/ does not resolve to any page and also does not support httpS.

maybe this link is outdated and can be removed.

Incorrect dragging behavior

Describe the bug
Incorrect behavior when dragging slider on its first and last slide, of course this only happens if you are using the extended version of the lib.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'https://swiffyslider.com/configuration/?slider-nav-mousedrag=slider-nav-mousedrag'
  2. On the first image, drag the slider from left to right.
  3. You will briefly see the second image on the slider, like we were dragging it from right to left, the reverse also happens if we are on the last image of the slider

Expected behavior
Either nothing or the slingshot effect, where you try to drag the slider, but as you release, it returns to its original position.

Screenshots
Recording 2022-07-27 at 00 34 27

Desktop

  • OS: Windows 11
  • Browser: Brave (Chromium)
  • Version: 1.41.100 Chromium: 103.0.5060.134 (Official Build) (64-bit)

Script skips images

Describe the bug
On a 5 image-slider, the script skips 2 and 4. You can see that the button list below is visited only on 1, 3 and 5. Why?

CleanShot 2022-04-21 at 08 15 11

The code is as follows:

<div id="employees" class="swiffy-slider slider-nav-outside slider-nav-visible slider-nav-nodelay slider-nav-autoplay slider-nav-autopause slider-item-show1 slider-indicators-outside slider-nav-animation slider-nav-animation-fadein slider-nav-animation-slow slider-item-last-visible" data-slider-nav-autoplay-interval="5000"> <ul class="slider-container"> <li class="employee"> <img src="https://info.spiria.com/hubfs/Erika.png" alt="Erika"> <div> <div id="hs_cos_wrapper_module_165049619677012_" class="hs_cos_wrapper hs_cos_wrapper_widget hs_cos_wrapper_type_inline_text" style="" data-hs-cos-general-type="widget" data-hs-cos-type="inline_text" data-hs-cos-field="employee_title"></div><br>Erika </div> </li> [...] </ul> <button type="button" class="slider-nav"></button> <button type="button" class="slider-nav slider-nav-next"></button> <div class="slider-indicators"> <button class=""></button> <button></button> <button class=""></button> <button></button> <button class="active"></button> </div> </div>

The script is fired this way:

window.addEventListener('load', () => { swiffyslider.initSlider(document.getElementById('employees')); });

close button for full screen image carousel

I found it hard to close the full screen carousel since there is no close button in the top corner. After I hit "escape" and read the directions though, it made sense.

Add an option to see a close icon in top right to make closing full screen more intuitive. Now, clicking in top right advances to next slide.

If this is an easy addition on my side with scripting, no need to bake into the code.

Thank you! Very clean documentation.

Allow styling of slider-indicators with classes

Is your feature request related to a problem? Please describe.
It's difficult to style slider-indicator buttons because all of their classes are stripped when adding/removing the active class. I'm trying to dynamically style these using Tailwind, so using CSS / inline styles aren't really an option.

Describe the solution you'd like
Check if the element has the active class, then selectively remove that class instead of removing the entire class attribute.

Loving the simplicity of this slider, just want to be able to implement more color customization options beyond light & dark.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.