Coder Social home page Coder Social logo

recidvst / scrub-slider Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 0.0 1.56 MB

JS library for adding a scrubber-style slider component for images.

Home Page: https://recidvst.github.io/scrub-slider/

License: MIT License

HTML 37.59% JavaScript 10.84% SCSS 14.78% CSS 6.93% Shell 0.27% TypeScript 29.59%
featured front-end javascript js npm scrub scrub-slider scrubber slider slider-component

scrub-slider's Introduction

npm npm license

Scrub Slider

A lightweight javascript library that lets you 'scrub' transition between two images with style.

Demo Page

Install

  • Install the package from NPM or Yarn.
  • Or download manually from Github.
npm install scrub-slider

JS

Either import the JS as a module:

import Scrub from "scrub-slider";

Or consume the module as UMD/IIFE

<script src="./scrub.iife.js"></script>

CSS

Either import the CSS into your JS/CSS:

import "scrub-slider/dist/scrub.css";
@import "scrub-slider/dist/scrub.css";

Or include it the old fashioned way:

<link href="./scrub.css" rel="stylesheet" />

Usage

Scrub needs to be passed a containing element plus two images to work

  • Initiate a Scrub instance by calling Scrub() with a valid selector (of the parent element). This is best as an ID but a unique class is fine too.
  • If you wish to configure your slider, pass Scrub() an object with config options (see below).
  • You have a choice for how you want to pass the two images:
    • <img> with src properties
    • <div> with background-image set on the html
    • any tag (empty), with image specified with the src config property
  • Edit the css provided to add your own styling e.g. to the handle
  • The container should have a width.

Configure

You can configure your Scrub instance by passing your selector and some config parameters as an object. The available options are as follows:

Target

Purpose: This is the item which you wish to become a Scrub slider! Pass the id or unique class of a container element.
Type: string
Default: null
Required: Yes.

Height

Purpose: This is the height of your Scrub instance. Defaults to 500px. Specify height in pixels.
Type: string
Default: 500px
Required: No. But recommended.

Handle

Purpose: This is the switch for the circular handle control on the slider's dividing line. Set to false to hide. If you want to style this differently, add your own css on '.sliding'.
Type: bool
Default: true
Required: No.

Src

Purpose: Alternate method of specifying slider images. Pass an array of two strings containing an img src. Left then right.
Type: array
Default: null
Required: No. As long as the element you want to instantiate as a Scrub slider is an image with valid src property or a div with a valid background-image property.

Alt

Purpose: Add an alt tag to the slider. Pass an array of two strings describing each image. Left then right.
Type: array
Default: null
Required: No.

Example

Scrub({
  target: "#slider1",
  height: "500",
  handle: true,
  src: [
    "https://raw.github.com/Recidvst/recidvst-images/master/mustang-old-min.jpg",
    "https://raw.github.com/Recidvst/recidvst-images/master/mustang-old-inverted-min.jpg",
  ],
  alt: ["Image number 1 alt", "Image number 2 alt"],
});

scrub-slider's People

Contributors

recidvst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.