0.2.5 • Published 1 year ago

simpleslider-ssjs v0.2.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Simple Slider

Demo

Overview

npm bundle size

NPM

GitHub commit activity

GitHub all releases

npm

What is Simple Slider

  • Simple Slider is a basic Vanilla JS carousel

Quick Start

First install the package

npm i simpleslider-ssjs

Then go to example.html and browse example.

As an alternative you can browse React Example

Getting started

<html>
    <head>
    </head>
    <body>
        <div id="mySlider">
            place your elements here..
        </div>
        <script type="module">
            import { simpleSlider } from 'simpleslider-ssjs';
            const options = {
                ... specialize the options or you can prefer to use defaults
                .. you can see the all options on  #Parameters section
            }

            const SimpleSlider = simpleSlider.init(options);
        </script>
    </body>
</html>

That's all. Now you can manipulate simpleSlider by using your SimleSlider constant.

Events

on:

    const handler = (index) => { 
        console.log('active slide is:', index+1); 
    }
    slider.on('changed', handler);
  • When slide changes, the carousel will trigger the handler function. This event could be usefull when you want to know which slide is seen by user or want to manipulate the DOM.

IMPORTANT NOTE: If you set more than 1 slide per page in options this event will return only the first slide's index which seen by user

Methods

init:

this is the most basic method to initialize your container element

    import { simpleSlider } from 'simpleslider-ssjs';

    simpleSlider.init(options)

goToSlide:

    import { simpleSlider } from 'simpleslider-ssjs';

    ...initial code blocks

    const nextButtonHandler = () => { 
        slider.goToSlide('>');
    }

    const previousButtonHandler = () => { 
        slider.goToSlide('<');
    }
    
    const navigationButtonHandler = (index) => { 
        slider.goToSlide(index);
    }
  • if you want to manipulate slider from other elements click events etc. this event could be usefull. This event accepts integer and > < strings as a parameter. If you prefer to set true noControl option you can handle next prev and navigation buttons by this method. < means previous slide and > means next slide.

getActiveSlide:

    import { simpleSlider } from 'simpleslider-ssjs';
    
    ... initial code blocks

    console.log(slider.getActiveSlide());
  • You can get active index with this event

Parameters (options)

OptionTypeIs ParentDefaultIs NeededDescription
containerHTML ELEMENTnullYesThis parameter need to be supplied for initialization. This must to be your main slider container
imgListArray of strings[]Only if there is no child element in container or didn't supplied itemListImg url list
itemListArray of HTML ELEMENTSundefinedOnly if there is no child element in container or didn't supplied imgListHtml elements array
createCustomControlsBooleanundefinedNoThis is experimental till getting improved not to use is better
noControlBooleanundefinedNoFor creating yout custom next prev buttons etc. set this to true
controlsObject{ next: false, prev: false, navigation: false, }Only needed if createCustomControls is trueThis is connected with createCustomControls so same with it
nextHTML ELEMENTChild of controlsfalseOnly needed if createCustomControls is true--
prevHTML ELEMENTChild of controlsfalseOnly needed if createCustomControls is true--
navigationHTML ELEMENTChild of controlsfalseOnly needed if createCustomControls is true--
autoPlayBooleantrueNoIf don't you set it false slides will change in every 4 seconds.
autoPlayDurationNumber4000NoIf you set the autoplay option to true and prefer to change the autoplay duration you can set this
styleObject{ boxSizing: 'border-box', border: '1px solid gray', borderRadius: '12px', }NoThis option created for flexibility. You can set every key about css styles and all of them will applied to container element dynamically. For example width height marginTop borderRadius... There are only two things you can not set with this option. 1.) display (flex as default) and 2.) overflow hidden as default
slidePerPageNumber1NoHow many slides do you want to show to user ?
gapString or Number0NoThis is the gap between each slide. This will get applied if slidePerPage option is bigger than 1. You can set it as integer or '1rem' || 12 || "15px". only px and rem supportted. If it is number then it'll agreed as px
0.2.3

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago