Giter Club home page Giter Club logo

switch's Introduction

Switch

Build Status Coverage Status

๐Ÿฐ A simple and powerful iOS style switch for checkbox.

Live Preview

Installation

Standalone:
<link rel="stylesheet" href="dist/switch.css" />
<script src="dist/switch.js"></script>
npm:
$ npm install weatherstar-switch --save-dev

Usage

<input type="checkbox" class="checkbox-switch" />

standalone version

var el = document.querySelector('.checkbox-swtich');
var mySwitch = new Switch(el, options);

work with module bundle

require('weatherstar-switch/dist/switch.css');
var Switch = require('weatherstar-switch');

var el = document.querySelector('.checkbox-swtich');
var mySwitch = new Switch(el, options);

Settings and Defaults

defaults = {
    size             : 'default'
  , checked          : undefined
  , onText           : 'Y'
  , offText          : 'N'
  , onSwitchColor    : '#64BD63'
  , offSwitchColor   : '#fff'
  , onJackColor      : '#fff'
  , offJackColor     : '#fff'
  , showText         : false
  , disabled         : false
  , onInit           : function(){}
  , onChange         : function(){}
  , onRemove         : function(){}
  , onDestroy        : function(){}
};
  • size : size of switch element, can be default | small | large
  • checked : state of switch and checbox, if undefined the switch state according to the checkbox
  • onText : text in the jack when switch ON
  • offText : text in the jack when switch OFF
  • onSwitchColor : color of checked switch element
  • offSwitchColor : color of unchecked switch element
  • onJackColor : color of checked jack element
  • offJackColor : color of unchecked jack element
  • showText : show or hide text in the jack of switch
  • disabled : enable or disable click events and changing the state of the switch
  • onInit : called when switch init finish
  • onChange : called when original checkbox's checked change
  • onRemove : called when mySwitch.remove()
  • onDestroy : called when mySwitch.destroy()

API

.on()

Set switch ON.

.off()

Set switch OFF.

.toggle()

Toggle switch.

.disable()

Disable events bind to switch.

.enable()

Enable events bind to switch.

.destroy()

Remove all events bind to switch.

.remove()

Remove switch form DOM and show the checkbox.

License

MIT ยฉ zhiyul

switch's People

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.