PHPackages                             levmyshkin/tiny-slider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. levmyshkin/tiny-slider

ActiveDrupal-library

levmyshkin/tiny-slider
======================

Fork from ganlanyuan/tiny-slider. Tiny slider for all purposes, inspired by Owl Carousel.

2.9.5(4y ago)117.8k↓36%MITHTML

Since Nov 28Pushed 4y agoCompare

[ Source](https://github.com/levmyshkin/tiny-slider)[ Packagist](https://packagist.org/packages/levmyshkin/tiny-slider)[ RSS](/packages/levmyshkin-tiny-slider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Tiny Slider 2
=============

[](#tiny-slider-2)

[![](https://camo.githubusercontent.com/97317198204b36dd5b89cecc2cb789930c98e6ea7a788a3fe72028f2c92a5136/68747470733a2f2f646174612e6a7364656c6976722e636f6d2f76312f7061636b6167652f6e706d2f74696e792d736c696465722f62616467653f7374796c653d726f756e646564)](https://www.jsdelivr.com/package/npm/tiny-slider)[![version](https://camo.githubusercontent.com/450e825eb853eddb1b5c27bd3a24ec4a4b0ffe6b76d3311808e80b03488bc228/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d322e392e342d677265656e2e737667)](https://camo.githubusercontent.com/450e825eb853eddb1b5c27bd3a24ec4a4b0ffe6b76d3311808e80b03488bc228/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d322e392e342d677265656e2e737667)

Tiny slider for all purposes, inspired by [Owl Carousel](https://owlcarousel2.github.io/OwlCarousel2/).

[Demos](http://ganlanyuan.github.io/tiny-slider/demo)

[Test results](http://ganlanyuan.github.io/tiny-slider/test)

*Previous versions*: [v1](https://github.com/ganlanyuan/tiny-slider/tree/v1), [v0](https://github.com/ganlanyuan/tiny-slider/tree/v0)

**Warning**: tiny-slider works with static content and it works in the browser only. If the HTML is loaded dynamically, make sure to call `tns()` after its loading.

Contents
--------

[](#contents)

- [What's new](#whats-new)
- [Features](#features)
- [Install](#install)
- [Usage](#usage)
- [Options](#options)
- [Responsive options](#responsive-options)
- [Methods](#methods)
- [Custom Events](#custom-events)
- [Fallback](#fallback)
- [Browser Support](#browser-support)
- [Support](#support)
- [License](#license)

What's new
----------

[](#whats-new)

- Using `%` instead of `px` (No more recalculation of each slide width on window resize)
- Using CSS Mediaqueries if supported
- Save browser capability values to [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), so they will not be recheck again until browser get upgraded or user clear the localStorage manually.
- More options available for `responsive`. (Start from [v2.1.0](https://github.com/ganlanyuan/tiny-slider/releases/tag/v2.1.0), [issue 53](https://github.com/ganlanyuan/tiny-slider/issues/53))
- Insert `controls` and `nav` *before* slider instead of after ([issue 4](https://github.com/ganlanyuan/tiny-slider/issues/4))
- Move `autoplay` button out of `nav` container. (Start from [v2.1.0](https://github.com/ganlanyuan/tiny-slider/releases/tag/v2.1.0))
- Some selector changes in [`tiny-slider.scss`](https://github.com/ganlanyuan/tiny-slider/blob/master/src/tiny-slider.scss)

*Migrating to v2*

- Update `controls` and / or `nav` styles based on their position changes.
- Update the [`slider selectors`](https://github.com/ganlanyuan/tiny-slider/blob/master/src/tiny-slider.scss) accordingly if used in your CSS or JS.
- Update styles related to `autoplay` button.

*[top↑](#tiny-slider-2)*

Features
--------

[](#features)

     Carousel \* Gallery   Horizontal \* Vertical   Percentage Width \* Fixed Width Auto Width     Loop ✓ ✓ ✓ ✓ ✓   Rewind ✓ ✓ ✓ ✓     Slide by ✓ ✓ ✓ ✓     Gutter ✓ ✓ ✓ ✓ ✓   Edge padding ✓ ✓ ✓ ✓     Center (v2.9.2+) ✓ ✓ ✓       Responsive ✓ ✓ ✓ ✓ ✓   Lazyload ✓ ✓ ✓ ✓ ✓   Autoplay ✓ ✓ ✓ ✓ ✓   Auto height ✓ ✓ ✓ ✓ ✓   Touch/drag ✓ ✓ ✓ ✓ ✓   Arrow keys ✓ ✓ ✓ ✓ ✓   Customize controls/nav ✓ ✓ ✓ ✓ ✓   Accessibility ✓ ✓ ✓ ✓ ✓   Respond to DOM visibility changes ✓ ✓ ✓ ✓ ✓   Custom events ✓ ✓ ✓ ✓ ✓   Nested ✓ ✓ ✓ ✓ ✓  \* Default *[top↑](#tiny-slider-2)*

Install
-------

[](#install)

`bower install tiny-slider` or `npm install tiny-slider`

Usage
-----

[](#usage)

#### 1. Add CSS (and IE8 polyfills if needed)

[](#1-add-css-and-ie8-polyfills-if-needed)

```

```

#### 2. Add markup

[](#2-add-markup)

```

```

#### 3. Call tns()

[](#3-call-tns)

Option A: Add tiny-slider.js to your page:

```

```

Option B: Import `tns` via `webpack` or `rollup`:

```
// yourScript.js
import { tns } from "./node_modules/tiny-slider/src/tiny-slider"
```

Option C: Import `tns` directly start from v2.8.2

```

  import {tns} from './src/tiny-slider.js';

  var slider = tns({
    container: '.my-slider',
    items: 3,
    slideBy: 'page',
    autoplay: true
  });

```

*[top↑](#tiny-slider-2)*

Options
-------

[](#options)

OptionTypeDescription`container`Node | StringDefault: `'.slider'`.
 The slider container element or selector.`mode`"carousel" | "gallery"Default: "carousel".
 Controls animation behaviour.
 With `carousel` everything slides to the side, while `gallery` uses fade animations and changes all slides at once.`axis`"horizontal" | "vertical"Default: "horizontal".
 The axis of the slider.`items`positive numberDefault: 1.
 Number of slides being displayed in the viewport.
 If slides less or equal than `items`, the slider won't be initialized.`gutter`positive integerDefault: 0.
 Space between slides (in "px").`edgePadding`positive integerDefault: 0.
 Space on the outside (in "px").`fixedWidth`positive integer | falseDefault: false.
 Controls `width` attribute of the slides.`autoWidth`BooleanDefault: false.
 If `true`, the width of each slide will be its natural width as a `inline-block` box.`viewportMax` (was `fixedWidthViewportWidth`)positive integer | falseDefault: false.
 Maximum viewport width for `fixedWidth`/`autoWidth`.`slideBy`positive number | "page"Default: 1.
 Number of slides going on one "click".`center` (v2.9.2+)BooleanDefault: false.
 Center the active slide in the viewport.`controls`BooleanDefault: true.
 Controls the display and functionalities of `controls` components (prev/next buttons). If `true`, display the `controls` and add all functionalities.
For better accessibility, when a prev/next button is focused, user will be able to control the slider using left/right arrow keys.`controlsPosition`"top" | "bottom"Default: "top".
 Controls `controls` position.`controlsText`(Text | Markup) ArrayDefault: \["prev", "next"\].
 Text or markup in the prev/next buttons.`controlsContainer`Node | String | falseDefault: false.
 The container element/selector around the prev/next buttons.
 `controlsContainer` must have at least 2 child elements.`prevButton`Node | String | falseDefault: false.
 Customized previous buttons.
 This option will be ignored if `controlsContainer` is a Node element or a CSS selector.`nextButton`Node | String | falseDefault: false.
 Customized next buttons.
 This option will be ignored if `controlsContainer` is a Node element or a CSS selector.`nav`BooleanDefault: true.
 Controls the display and functionalities of `nav` components (dots). If `true`, display the `nav` and add all functionalities.`navPosition`"top" | "bottom"Default: "top".
 Controls `nav` position.`navContainer`Node | String | falseDefault: false.
 The container element/selector around the dots.
 `navContainer` must have at least same number of children as the slides.`navAsThumbnails`BooleanDefault: false.
 Indicate if the dots are thumbnails. If `true`, they will always be visible even when more than 1 slides displayed in the viewport.`arrowKeys`BooleanDefault: false.
 Allows using arrow keys to switch slides.`speed`positive integerDefault: 300.
 Speed of the slide animation (in "ms").`autoplay`BooleanDefault: false.
 Toggles the automatic change of slides.`autoplayPosition`"top" | "bottom"Default: "top".
 Controls `autoplay` position.`autoplayTimeout`positive integerDefault: 5000.
 Time between 2 `autoplay` slides change (in "ms").`autoplayDirection`"forward" | "backward"Default: "forward".
 Direction of slide movement (ascending/descending the slide index).`autoplayText`Array (Text | Markup)Default: \["start", "stop"\].
 Text or markup in the autoplay start/stop button.`autoplayHoverPause`BooleanDefault: false.
 Stops sliding on mouseover.`autoplayButton`Node | String | falseDefault: false.
 The customized autoplay start/stop button or selector.`autoplayButtonOutput`BooleanDefault: true.
 Output `autoplayButton` markup when `autoplay` is true but a customized `autoplayButton` is not provided.`autoplayResetOnVisibility`BooleanDefault: true.
 Pauses the sliding when the page is invisible and resumes it when the page become visiable again. ([Page Visibility API](https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API))`animateIn`StringDefault: "tns-fadeIn".
 Name of intro animation `class`.`animateOut`StringDefault: "tns-fadeOut".
 Name of outro animation `class`.`animateNormal`StringDefault: "tns-normal".
 Name of default animation `class`.`animateDelay`positive integer | falseDefault: false.
 Time between each `gallery` animation (in "ms").`loop`BooleanDefault: true.
 Moves throughout all the slides seamlessly.`rewind`BooleanDefault: false.
 Moves to the opposite edge when reaching the first or last slide.`autoHeight`BooleanDefault: false.
 Height of slider container changes according to each slide's height.`responsive`Object: {
 breakpoint: {
 key: value
 }
} | falseDefault: false.
Breakpoint: Integer.
Defines options for different viewport widths (see [Responsive Options](#responsive-options)).
`lazyload`BooleanDefault: false.
 Enables lazyloading images that are currently not viewed, thus saving bandwidth (see [demo](http://ganlanyuan.github.io/tiny-slider/demo/#lazyload_wrapper)).
 NOTE:
+ Class `.tns-lazy-img` need to be set on every image you want to lazyload if option `lazyloadSelector` is not specified;
+ `data-src` attribute with its value of the real image `src` is required;
+ `width` attribute for every image is required for `autoWidth` slider.`lazyloadSelector` (v2.9.1+)StringDefault: `'.tns-lazy-img'`.
 The CSS selector for lazyload images.`touch`BooleanDefault: true.
 Activates input detection for touch devices.`mouseDrag`BooleanDefault: false.
 Changing slides by dragging them.`swipeAngle`positive integer | BooleanDefault: 15.
 Swipe or drag will not be triggered if the angle is not inside the range when set.`preventActionWhenRunning` (v2.9.1+)BooleanDefault: false.
 Prevent next transition while slider is transforming.`preventScrollOnTouch` (v2.9.1+)"auto" | "force" | falseDefault: false.
 Prevent page from scrolling on `touchmove`. If set to "auto", the slider will first check if the touch direction matches the slider axis, then decide whether prevent the page scrolling or not. If set to "force", the slider will always prevent the page scrolling.`nested`"inner" | "outer" | falseDefault: false.
 Define the relationship between nested sliders. (see [demo](http://ganlanyuan.github.io/tiny-slider/demo/#nested_wrapper))
Make sure you run the inner slider first, otherwise the height of the inner slider container will be wrong.`freezable`BooleanDefault: true.
 Indicate whether the slider will be frozen (`controls`, `nav`, `autoplay` and other functions will stop work) when all slides can be displayed in one page.`disable`BooleanDefault: false.
 Disable slider.`startIndex`positive integerDefault: 0.
 The initial `index` of the slider.`onInit`Function | falseDefault: false.
 Callback to be run on initialization.`useLocalStorage`BooleanDefault: true.
 Save browser capability variables to [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) and without detecting them everytime the slider runs if set to `true`.`nonce`String / falseDefault: false.
 Optional Nonce attribute for inline style tag to allow slider usage without `unsafe-inline Content Security Policy source.NOTE: Prior to v2.0.2, options "container", "controlsContainer", "navContainer" and "autoplayButton" still need to be DOM elements. E.g. container: document.querySelector('.my-slider')

*[top↑](#tiny-slider-2)*

Responsive options
------------------

[](#responsive-options)

The following options can be redefined in `responsive` field: `startIndex`, `items`, `slideBy`, `speed`, `autoHeight`, `fixedWidth`, `edgePadding`, `gutter`, `center`, `controls`, `controlsText`, `nav`, `autoplay`, `autoplayHoverPause`, `autoplayResetOnVisibility`, `autoplayText`, `autoplayTimeout`, `touch`, `mouseDrag`, `arrowKeys`, `disable`

```

  var slider = tns({
    container: '.my-slider',
    items: 1,
    responsive: {
      640: {
        edgePadding: 20,
        gutter: 20,
        items: 2
      },
      700: {
        gutter: 30
      },
      900: {
        items: 3
      }
    }
  });

```

NOTE:

- The breakpoints behave like `(min-width: breakpoint)` in CSS, so an undefined option will be inherited from previous small breakpoints.
- `fixedWidth` can only be changed to other positive integers. It can't be changed to negative integer, 0 or other data type. *[top↑](#tiny-slider-2)*

Methods
-------

[](#methods)

The slider returns a slider object with some properties and methods once it's initialized:

```
{
  version: version, // tiny-slider version
  getInfo: info(),
  events: events, // Object
  goTo: goTo(),
  play: play(),
  pause: pause(),
  isOn: isOn, // Boolean
  updateSliderHeight: updateInnerWrapperHeight(),
  refresh: initSliderTransform(),
  destroy: destroy(),
  rebuild: rebuild()
}
```

To get the slider information, you can either use the `getInfo()` method or subscribe to an Event. Both return an Object:

```
{
                container: container, // slider container
               slideItems: slideItems, // slides list
             navContainer: navContainer, // nav container
                 navItems: navItems, // dots list
        controlsContainer: controlsContainer, // controls container
              hasControls: hasControls, // indicate if controls exist
               prevButton: prevButton, // previous button
               nextButton: nextButton, // next button
                    items: items, // items on a page
                  slideBy: slideBy // items slide by
               cloneCount: cloneCount, // cloned slide count
               slideCount: slideCount, // original slide count
            slideCountNew: slideCountNew, // total slide count after initialization
                    index: index, // current index
              indexCached: indexCached, // previous index
             displayIndex: getCurrentSlide(), // display index starts from 1
               navCurrent: navCurrent, // current dot index
         navCurrentCached: navCurrentCached, // previous dot index
                    pages: pages, // visible nav indexes
              pagesCached: pagesCached,
                    sheet: sheet,
                    event: e || {}, // event object if available
};
```

#### getInfo

[](#getinfo)

Get slider information.

```
slider.getInfo();

document.querySelector('.next-button').onclick = function () {
  // get slider info
  var info = slider.getInfo(),
      indexPrev = info.indexCached,
      indexCurrent = info.index;

  // update style based on index
  info.slideItems[indexPrev].classList.remove('active');
  info.slideItems[indexCurrent].classList.add('active');
};
```

#### goTo

[](#goto)

Go to specific slide by number or keywords.

```
slider.goTo(3);
slider.goTo('prev');
slider.goTo('next');
slider.goTo('first');
slider.goTo('last');

document.querySelector('.goto-button').onclick = function () {
  slider.goTo(3);
};
```

#### play

[](#play)

Programmatically start slider autoplay when `autoplay: true`.

```
slider.play();
```

#### pause

[](#pause)

Programmatically stop slider autoplay when `autoplay: true`.

```
slider.pause();
```

#### updateSliderHeight

[](#updatesliderheight)

Manually adjust slider height when `autoHeight` is `true`.

```
slider.updateSliderHeight();
```

#### destroy

[](#destroy)

Destroy the slider.

```
slider.destroy();
```

#### rebuild

[](#rebuild)

Rebuild the slider after destroy.

```
slider = slider.rebuild();
// this method returns a new slider Object with the same options with the original slider
```

Custom Events
-------------

[](#custom-events)

Available events include: `indexChanged`, `transitionStart`, `transitionEnd`, `newBreakpointStart`, `newBreakpointEnd`, `touchStart`, `touchMove`, `touchEnd`, `dragStart`, `dragMove` and `dragEnd`.

```
var customizedFunction = function (info, eventName) {
  // direct access to info object
  console.log(info.event.type, info.container.id);
}

// bind function to event
slider.events.on('transitionEnd', customizedFunction);

// remove function binding
slider.events.off('transitionEnd', customizedFunction);
```

*[top↑](#tiny-slider-2)*

#### Fallback

[](#fallback)

```
.no-js .your-slider { overflow-x: auto; }
.no-js .your-slider > div { float: none; }
```

Browser Support
---------------

[](#browser-support)

**Desktop:**Firefox 8+ ✓ Chrome 15+ ✓ (Should works on *Chrome 4-14* as well, but I couldn't test it.) Safari 4+ ✓ Opera 12.1+ ✓ IE 8+ ✓

**Mobile:**Android Browser 4.2+ ✓ Chrome Mobile 63+ ✓ Firefox Mobile 28+ ✓ Maxthon 4+ ✓

Support
-------

[](#support)

[![Browser Stack](logos/browserstack.svg)](https://www.browserstack.com/)
Live tests and Automated Tests

[![Cross Browser Testing](logos/cbt.svg)](https://crossbrowsertesting.com/)
Live tests, Screenshots and Automated Tests

[Cdnjs](https://cdnjs.com/)
Images on demo page are from .

License
-------

[](#license)

This project is available under the [MIT](https://opensource.org/licenses/mit-license.php) license.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1632d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b36520942f79193ba42311edf66bce9654c126a2d6733a5b3a627a4a217229f?d=identicon)[levmyshkin](/maintainers/levmyshkin)

---

Top Contributors

[![ganlanyuan](https://avatars.githubusercontent.com/u/4998811?v=4)](https://github.com/ganlanyuan "ganlanyuan (1010 commits)")[![Raiondesu](https://avatars.githubusercontent.com/u/19854420?v=4)](https://github.com/Raiondesu "Raiondesu (6 commits)")[![scottleblang](https://avatars.githubusercontent.com/u/47985245?v=4)](https://github.com/scottleblang "scottleblang (4 commits)")[![Jamie0](https://avatars.githubusercontent.com/u/7827627?v=4)](https://github.com/Jamie0 "Jamie0 (3 commits)")[![daphnesmit](https://avatars.githubusercontent.com/u/4718795?v=4)](https://github.com/daphnesmit "daphnesmit (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![openscript](https://avatars.githubusercontent.com/u/1105080?v=4)](https://github.com/openscript "openscript (3 commits)")[![aberezkin](https://avatars.githubusercontent.com/u/3759233?v=4)](https://github.com/aberezkin "aberezkin (2 commits)")[![floq-design](https://avatars.githubusercontent.com/u/134165?v=4)](https://github.com/floq-design "floq-design (2 commits)")[![matt3188](https://avatars.githubusercontent.com/u/8866024?v=4)](https://github.com/matt3188 "matt3188 (2 commits)")[![romelgomez](https://avatars.githubusercontent.com/u/2358251?v=4)](https://github.com/romelgomez "romelgomez (2 commits)")[![S1SYPHOS](https://avatars.githubusercontent.com/u/12161504?v=4)](https://github.com/S1SYPHOS "S1SYPHOS (2 commits)")[![tzsk](https://avatars.githubusercontent.com/u/13273787?v=4)](https://github.com/tzsk "tzsk (2 commits)")[![wroughtec](https://avatars.githubusercontent.com/u/74549?v=4)](https://github.com/wroughtec "wroughtec (2 commits)")[![nghiepdev](https://avatars.githubusercontent.com/u/4768095?v=4)](https://github.com/nghiepdev "nghiepdev (1 commits)")[![notiv-nt](https://avatars.githubusercontent.com/u/10743009?v=4)](https://github.com/notiv-nt "notiv-nt (1 commits)")[![DimaGashko](https://avatars.githubusercontent.com/u/20650419?v=4)](https://github.com/DimaGashko "DimaGashko (1 commits)")[![przemkow](https://avatars.githubusercontent.com/u/10272880?v=4)](https://github.com/przemkow "przemkow (1 commits)")[![crenshaw-dev](https://avatars.githubusercontent.com/u/350466?v=4)](https://github.com/crenshaw-dev "crenshaw-dev (1 commits)")[![reubano](https://avatars.githubusercontent.com/u/157864?v=4)](https://github.com/reubano "reubano (1 commits)")

### Embed Badge

![Health badge](/badges/levmyshkin-tiny-slider/health.svg)

```
[![Health](https://phpackages.com/badges/levmyshkin-tiny-slider/health.svg)](https://phpackages.com/packages/levmyshkin-tiny-slider)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
