Giter Club home page Giter Club logo

slider's Introduction

Box Slider

A modern, light weight content slider

NPM Status Build Status

About

BoxSlider is a small library with zero dependencies that provides a light-weight, responsive content slider with various slide transition effects for modern browsers.

The library can be used standalone or by using the Web and React components.

Installation

Install from NPM

npm install --save @boxslider/slider

Use from CDN

<script type="module">
  import {
    BoxSlider,
    FadeSlider,
  } from 'https://cdn.jsdelivr.net/npm/@boxslider/slider/+esm'

  const slider = new BoxSlider(
    document.getElementById('slider'),
    new FadeSlider(),
  )
</script>

Web Components

Install via NPM

npm install --save @boxslider/components

Use from CDN

<script
  type="module"
  src="https://cdn.jsdelivr.net/npm/@boxslider/components/+esm"></script>

<bs-carousel>
  <!-- Slides -->
</bs-carousel>

View the @boxslider/components package for full details.

React

Install via NPM

npm install --save @boxslider/react

View the @boxslider/react package for full details. Eact React component is a thin wrapper around the Web Component for that effect.

Usage

Create the HTML structure for your content. Some effects require each slide to only contain an image but others support any form of content. See the documentation for the desired effect for detailed instructions.

<section id="content-box">
  <!-- the content box -->
  <figure>
    <!-- slide one -->
    <picture>
      <source srcset="one-680.jpg" media="(min-width: 800px)" />
      <img src="one.jpg" />
    </picture>
    <figcaption>This is slide one</figcaption>
  </figure>
  <figure>
    <!-- slide two -->
    <picture>
      <source srcset="two-680.jpg" media="(min-width: 800px)" />
      <img src="two.jpg" />
    </picture>
    <figcaption>This is slide two</figcaption>
  </figure>
  <figure>
    <!-- slide three -->
    <picture>
      <source srcset="three-680.jpg" media="(min-width: 800px)" />
      <img src="three.jpg" />
    </picture>
    <figcaption>This is slide three</figcaption>
  </figure>
</section>

To initialize the slider from JavaScript select the box and create a new BoxSlider instance with the desired settings and effect.

import { BoxSlider, FadeSlider } from '@boxslider/slider'

const options = {
  autoScroll: true,
  timeout: 5000,
}
const box = document.querySelector('#content-box')

// Create a fading slide transition that moves to the next slide every 5 seconds (5000ms)
const slider = new BoxSlider(box, new FadeSlider(), options)

// Call API methods on the slider to manipulate it see documentation for available actions
slider.next().then(() => {
  // Promise resolves when the box has transitioned to the next slide
})

Options

  • speed: number (default: 800) The time interval in milliseconds within which the slide animation will complete
  • autoScroll: boolean (default: true) Set true to automatically transition through the slides
  • timeout: number (default: 5000) The time interval between slide transitions. For use with autoScroll
  • pauseOnHover: boolean (default: false) Pause an auto-scrolling slider when the users mouse hovers over it. For use with autoScroll or a slider in play mode.
  • swipe: boolean (default: true) Enable swiping the box to navigate to the next or previous slide.
  • swipeTolerance: number (default 30) The number of pixels between the pointer down and pointer up events during the swipe action that will trigger the transition.

Effect Options

CubeSlider

  • direction: 'horizontal' | 'vertical' (default: horizontal) The direction in which the cube should rotate to the next slide.
  • perspective: number (default: 1000) The perspective to apply to the parent viewport element containing the box.

FadeSlider

  • timingFunction: string (default: ease-in) The CSS transition timing function to use when fading slide opacity.

TileSlider

  • tileEffect: 'fade' | 'flip' (default: flip) The transition effect for animating the tiles during slide transitions.
  • rows: number (default: 8) The number of tile rows into which the slide should be split
  • rowOffset: number (default: 50) The time offset for starting to animate the tiles in a row

CarouselSlider

  • timingFunction: string (default: ease-in-out) The CSS transition timing function to use when animating slides into position.
  • cover: boolean (default: false) If true sets the slide effect to cover over the previous slide.

Methods

skipTo

Shows a slide at the specified index starting from 0. Returns a promise that resolves when the transition is complete.

slider.skipTo(3).then(() => {
  // show 4th slide
  // transition complete
})

play

Start auto scrolling the slides

slider.play()

pause

Pause an already auto scrolling slider

slider.pause()

destroy

Destroys the slider and returns the HTML elements to their original state.

slider.destroy()

next

Moves the slider to the next slide. Returns a promise that resolves when the transition is complete.

slider.next().then(() => {
  // transition complete
})

prev

Moves the slider to the previous slide. Returns a promise that resolves when the transition is complete.

slider.prev().then(() => {
  // transition complete
})

reset

Re-initialises the slider with updated options. An updated effect may also be passed as the second parameter.

slider.reset(options, effect)

addEventListener

Adds a listener for the specified event. See the event documentation for the available events.

const afterTransitionListener = () => {
  // Take some action when the event occurs
}

slider.addEventListener('after', afterTransitionListener)

removeEventListener

Removes the listener for the specified event.

slider.removeEventListener('after', afterTransitionListener)

Events

before

Fires before each slide transition starts. The current and next indexes are supplied in the event data as well as the transition speed.

slider.addEventListener('before', (data) => {
  // data: {
  //   currentIndex: number
  //   nextIndex: number
  //   speed: number
  // }
})

after

Fires after each slide transition is complete. The active index is supplied in the event data

slider.addEventListener('after', (data) => {
  // data: {
  //   currentIndex: number
  //   speed: number
  // }
})

play

Fires when the slider is put into play mode.

slider.addEventListener('play', (data) => {
  // data: {
  //   currentIndex: number
  //   speed: number
  // }
})

pause

Fires when an autoScroll'ing slider is paused.

slider.addEventListener('pause', (data) => {
  // data: {
  //   currentIndex: number
  //   speed: number
  // }
})

destroy

Fires when a slider is destroyed.

slider.addEventListener('destroy', () => {
  // No event data
})

Accessibility

The slider will be applied with the aria-live="off" attribute when it is the autoScroll state and aria-live="polite" when slide transitions are being controlled externally. Each slide is given the aria-roledescription="slide" attribute but you will need to add aria-roledescription="carousel" to the container housing the slider and it's controls. An example implementation is shown below.

<section class="carousel" aria-roledescription="carousel">
  <div class="slider-controls">
    <button id="prev-slide" aria-controls="demo-slider">Previous slide</button>
    <button id="next-slide" aria-controls="demo-slider">Next slide</button>
    <button id="play" aria-controls="demo-slider">Play</button>
  </div>

  <div class="slider" id="demo-slider">
    <figure class="slide">
      <picture>
        <source srcset="happy-face-680.jpg" media="(min-width: 800px)" />
        <img src="happy-face.jpg" alt="Young boy with a smile on his face" />
      </picture>
    </figure>
    <figure class="slide">
      <img src="sad-face.jpg" alt="Old lady with a sad look on her face" />
    </figure>
    <figure class="slide">
      <img src="shocked-face.jpg" alt="Lady with a look of shock on her face" />
    </figure>
  </div>
</section>

<script>
  const slider = new BoxSlider(
    document.getElementById('demo-slider'),
    new CarouselSlider(),
    {
      autoScroll: false,
    },
  )

  document
    .getElementById('prev-slide')
    .addEventListener('click', () => slider.prev())
  // ... other button controls
</script>

slider's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar jason-cooke avatar p-m-p avatar renovate[bot] 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  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

slider's Issues

Correction

<script src="//code.jquery.com/jquery-1.7.2.min.js"></script>
after correct:
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
Now will work.

IE Microsoft Edge rotation

Hi, there is an issue with Vertical 3D Scroll at Microsoft Edge IE, that shows strange behavior on the 4th animation, somehow rotating in the wrong direction. Could you please give a hint how it can be solved?
Thanks.
Best regards
Dina

for future...

can you make onClick function to open Picture on full window size? wie on lightbox ??

it will bi powerfull..

tnx

slider not responsive

I tried this slider. The slider looks wonderful. But its not responsive. Can you make it responsive?

Update: I think its responsive. But not when I resize windows

Usability, aria attributs (request)

Hi,

I'm not enough skilled to findg where I can add some aria management to your plugin.

(I dont see how to use the 'onbefore' and 'onafter' callback.)

But could be done natively in the plugin itself.
Right when leaving the current slide I'd like to see probably something like this:
$currSlide.attr('aria-hidden','true');
$nextSlide.attr('aria-hidden','false');
While when arriving ton the next one hich becomes the current it shuold have the aria-hidden set to true when the slide is not visible or false when it's visible.

Thank you

TypeError: document.body is null

box-slider-all.jquery.min.js + Joomla 3.4.1
TypeError: document.body is null

FireBug shows at this location:
{var e=document.body.style,t="";return"webkit...

How to fix?
Thank you.

Fullscreen

Is it possible to make the slideshow fullscreen?

Love the plugin btw, very nice work!

License

Please add the license file for the code, otherwise it won't be possible to use it anywhere :)

drag & dropping the slides

hi, thanks for your plugin, is there any way i could drag and drop slides instead of clicking the next or preview button?
thanks

Responsive block

I have 100% width block, but when I change browser windows width size my block is didn't work 100% width http://i.imgur.com/x2gL2cX.png but if refresh page, block is set correctly.
How to fix and responsive block.

Not working.

Doesn't seem to work... I've put
$(document).ready(function(){
$('#content-box').boxSlider('');
});
At the beginning of box.slider.jquery.js but it doesn't work. Everything else is correctly set up.

Firefox rotation is broken

Firefox rotates from -90deg to -180deg through 270deg in the other direction as does rotating from 180deg to 270deg.

2D "Tile" transition to random

2D "Tile" transition, is it possible to make it random effect? I mean appearing random on every place instead of top to bottom/left to right? Thanks!

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3
  • changesets/action v1
.github/workflows/pr.yml
  • actions/checkout v4
  • actions/setup-node v4
  • pnpm/action-setup v3
npm
package.json
  • @types/node ^20.12.8
  • @changesets/cli ^2.27.1
  • @commitlint/cli ^19.3.0
  • @commitlint/config-conventional ^19.2.2
  • @testing-library/dom ^10.1.0
  • @testing-library/jest-dom ^6.4.5
  • @testing-library/user-event ^14.5.2
  • @types/react ^18.3.1
  • @types/react-dom ^18.3.0
  • @typescript-eslint/eslint-plugin ^7.8.0
  • @typescript-eslint/parser ^7.8.0
  • @vitejs/plugin-react ^4.2.1
  • @vitest/coverage-v8 ^1.6.0
  • @vitest/ui ^1.6.0
  • cz-conventional-changelog ^3.3.0
  • esbuild ^0.20.2
  • eslint ^8.57.0
  • eslint-config-prettier ^9.1.0
  • eslint-config-react-app ^7.0.1
  • eslint-plugin-react ^7.34.1
  • husky ^9.0.11
  • jsdom ^24.0.0
  • lint-staged ^15.2.2
  • prettier ^3.2.5
  • react ^18.3.1
  • react-dom ^18.3.1
  • typescript ^5.4.5
  • vite ^5.2.11
  • vitest ^1.6.0
packages/components/package.json
packages/react/package.json
  • react >=16.0.0
  • react-dom >=16.0.0
packages/slider/package.json
packages/website/package.json
  • lucide-react ^0.378.0
  • react-syntax-highlighter ^15.5.0
  • @types/react-syntax-highlighter ^15.5.13
  • autoprefixer ^10.4.19
  • postcss ^8.4.38
  • tailwindcss ^3.4.3

  • Check this box to trigger a request for Renovate to run again on this repository

Awful coding! aweful

Please, for god sake before you right down some code , do just few, just few research about other developer and how they doing, thanks

Swipe support for mobile device

Hi There,

Do you have any plan to update this for mobile device?
I put slider id as next, prev and change code on box-slider.jquery.js as swipeleft for next, swiperight for prev.

but, with autoscroll function when I swipe the slider it is interrupted by the autoscroll (because of it doesn't pause during i'm playing with it.)

If you have any plan to support this soon. will be awesome!

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.