New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cevad-tokatli/slider

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@cevad-tokatli/slider

Image slider for web and mobile browsers

1.0.0
unpublished
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Slider

Image Slider library for web and mobile browsers.

Intallation

It is available as a package on NPM for use with a module bundler.

# NPM
$ npm install --save @cevad-tokatli/slider

# Yarn
$ yarn add @cevad-tokatli/slider

Usage

You can simply import the module and create a new object with the Slider class.

import Slider from '@cevad-tokatli/slider'
import '@cevad-tokatli/slider/style.css'

const slider = new Slider({
  el: '#slider',
});

Configuration

Id

You can customize each element by assinging an id.

<div id="slider">
    <div class="ct-s-slider-element" ct-s-id="img1">Image-1</div>
    <div class="ct-s-slider-element" ct-s-id="img2">Image-2</div>
    <div class="ct-s-slider-element" ct-s-id="img3">Image-3</div>
</div>
import Slider, { SliderType } from '@cevad-tokatli/slider'

const slider = new Slider({
  el: '#slider',
  imagesSettings: [
    { id:'img1', sliderType: SliderType.Carousel },
    { id:'img2', sliderType: SliderType.Flow },
    { id:'img3', sliderType: SliderType.Fade },
  ]
})

Options

OptionTypeDefaultDescription
elstring | HTMLElement*nullContainer element.
timingstring"ease"Specifies the speed curve of an animation. Takes all the values CSS3 can take. (like ease, linear, cubic-bezier, step)
durationnumber800Defines how long an animation should take to complete one cycle. (as milliseconds)
sliderTypeSliderTypeCarouselSpecifies the animation type. It can be customized for each image element with the imagesSettings property.
touchMovebooleantrueEnables slide transitive with touch.
listbooleantrueDisplays a list at the bottom of the slider.
asListstring | HTMLUListElement | HTMLOListElement*nullDeclares the given list as the slider list.
arrowsbooleantrueDisplays right and left arrows to change the index.
asPrevArrowstring | HTMLElement*nullDeclares the given element as the prev arrow.
asNextArrowstring | HTMLElement*nullDeclares the given element as the next arrow.
autoPlaybooleanfalseEnables auto play of slides.
autoPlaySpeednumber5000Sets auto play interval. (as milliseconds)
imagesSettingsSliderElement[][]Customizes each element.

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

Slider Type

Specifies the slider animation type.

import Slider, { SliderType } from '@cevad-tokatli/slider'
As List

You can convert an HTML list element to a slider list that shows the current index and works as a pager.

  • It can be a ul or ol element.
  • It can be placed anywhere in the body.
  • List is updated when the index is changed.
  • Assigns ms-active class to list element that holds the current index.
<div id="slider">
    <div class="ct-s-slider-element" ct-s-id="img1">Image-1</div>
    <div class="ct-s-slider-element" ct-s-id="img2">Image-2</div>
    <div class="ct-s-slider-element" ct-s-id="img3">Image-3</div>
</div>
<ul id="list">
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
const slider = new Slider({
  el: '#slider',
  list: false,
  asList: '#list',
})

Callbacks

Before

before(current: SliderElement, next: SliderElement): Promise<boolean>
It is invoked before animation runs. It returns a promise so that animation waits for this mehtod to complete.

after(current: SliderElement, prev: SliderElement): Promise<boolean>
It is invoked after animation runs. It returns a promise so before the method completes running, another animation cannot run.

Each slider element also has an before and after method for themselves.

Events

EventDescription
touchStartFires when touching starts.
touchEndFires when touching ends.
changeFires when index changes.
playFires when autoplay starts.
stopFires when autoplay stops.
destroyFires when the slider is destroyed.
import Slider from '@cevat-tokatli/slider'

const slider = new Slider({
  el: '#slider',
})

slider.el.addEventListener('touchStart', () => {
  console.log('touching starts')
})

slider.el.addEventListener('touchEnd', () => {
  console.log('touching ends')
})

Methods

MethodParamsReturnDescription
addel: string | HTMLElement*
index: number
options: SliderElement
voidAdds a new element to the slider.
addFirstel: string | HTMLElement*
options: SliderElement
voidAdds a new element to the head of the slider.
addLastel: string | HTMLElement*
options: SliderElement
voidAdds a new element to the end of the slider.
removeindex: numbervoidRemoves the element at the specified index from the slider.
removeFirstvoidRemoves the first element from the slider.
removeLastvoidRemoves the last element from the slider.
prevPromise<boolean>Triggers the previous image. Returns false if the slider is in animation.
nextPromise<boolean>Triggers the next image. Returns false if the slider is in animation.
playvoidStarts autoplay.
stopvoidStops autoplay.
togglevoidToggles autoplay.
destroyvoidDestroys the slider.
getIndexnumberReturns index.
setIndexindex: numberPromise<boolean>Sets index and animates the slider. Returns false if the slider is in animation.
getTotalnumberReturns total number of images.
getCurrentSliderElementReturns the current element.
getTimingstringReturns timing value.
setTimingtiming: stringvoidSets timing value.
getDurationnumberReturns duration.
setDurationduration: numbervoidSets duration.
getAutoPlaySpeednumberReturns auto play speed.
setAutoPlaySpeedspeed: numbervoidSets auto play speed.

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

Slider Element

It is an object that holds one slider element.

Options

id {String}
Specifies the id of an image.

sliderType {SliderType}
Specifies the slider type of an image.

before(el: SliderElement, active:boolean): Promise<void>
It is invoked before animation runs. It returns a promise so animation waits for this method to complete. It is only invoked when it is the current or the next element. If it is the next element, active is true.

after(el: SliderElement, active:boolean): Promise<void>
It is invoked after animation runs. It returns a promise so before the method completes, another animation cannot run. It is only invoked when it is the current or the previous element. If it is the current element, active is true.

License

Slider is provided under the MIT License.

Keywords

typescript

FAQs

Package last updated on 15 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts