Giter Club home page Giter Club logo

pswitch's Introduction

pswitch

Turn boring checkboxes into cool-looking switches using pswitch.

Demo at http://www.pischke.me/pswitch/demo/pswitch.html

Usage instructions

pswitch is easy to integrate. It relies on jQuery, which you probably already have included in your project. Just add the stylesheet and javascript files (here in /dist) to your project page. If you use bower, you can add the project to your components.

    "pswitch": "[email protected]:thmp/pswitch.git"

To create a switch, call

$("input.pswitch").pswitch();

To display labels on the sides of the switch for the on and off state, define two data attributes on the checkbox. The switch will be displayed without labels if you do not specify them.

<input type="checkbox" class="pswitch" data-checked="Live" data-unchecked="Test" />

You can check the current state of the checkbox using the standard jQuery method.

$("input.pswitch").prop("checked");
// returns true or false

Blue does not fit your webpage style? To change the switch color, just pass the color code for the switch on creation to the pswitch function.

$("input.pswitch").pswitch({r: 25, g: 120, b: 30});

This would for example create a green switch.

To check or uncheck the checkbox programmatically, use jQuery to trigger the check or uncheck event on them.

// check a checkbox
$("input.pswitch").trigger("check");

// uncheck a checkbox
$("input.pswitch").trigger("uncheck");

// you can also toggle the state!
$("input.pswitch").trigger("toggle");

The switch also supports enabled and disabled states. You can manually set the checkbox state in the html before creating a pswitch or programmatically afterwards using these triggers.

// enable switch
$("input.pswitch").trigger("enable");

// disable switch
$("input.pswitch").trigger("disable");

Still to be implemented

  • When changing the data-on/off labels of a checkbox, the html labels should change accordingly
  • Include options to change size

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.