Code Monkey home page Code Monkey logo

bootstrap-toggle-buttons's Introduction

Bootstrap-toggle-buttons

Demo

http://www.larentis.eu/bootstrap_toggle_buttons/

Usage

Just include Twitter Bootstrap, jQuery and Bootstrap Toggle Buttons CSS and Javascript

<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
<link href="bootstrap-toggle-buttons.css" rel="stylesheet">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="jquery.toggle.buttons.js"></script>

Basic Example

HTML

<div id="toggle-button">
    <input id="checkbox1" type="checkbox" value="value1" checked="checked">
</div>

JS

$('#toggle-button').toggleButtons();

Full Example

HTML

<div id="toggle-button">
    <input id="checkbox1" type="checkbox" value="value1" checked="checked">
</div>

JS

$('#toggle-button').toggleButtons({
  onChange: function ($el, status, e) {
    // $el = $('#toggle-button'); 
    // status = [true, false], the value of the checkbox
    // e = the event
    console.log($el, status, e); 
  },
  width: 100,
  height: 25,
  font: {
    'font-size': '20px',
    'font-style': 'italic'
  },
  animated: true,
  transitionspeed: 1, // Accepted values float or "percent" [ 1, 0.5, "150%" ]
  label: {
    enabled: "ON",
    disabled: "OFF"
  },
  style: {
    // Accepted values ["primary", "danger", "info", "success", "warning"] or nothing
    enabled: "primary",
    disabled: "danger",
    custom: {
      enabled: {
        background:"#FF00FF",
        gradient: "#D300D3",
        color: "#FFFFFF"
      },
      disabled: {
        background: "#FFAA00",
        gradient: "#DD9900",
        color: "#333333"
      }
    }
  }
});

$('#toggle-button').toggleButtons('toggleActivation'); // to toggle the disabled status

Data Attributes Example

HTML

<div id="data-attribute-toggle-button"
     data-toggleButton-width="170"
     data-toggleButton-transitionspeed="500%"
     data-toggleButton-style-custom-enabled-background="#FF0000"
     data-toggleButton-style-custom-enabled-gradient="#000000">
    <input type="checkbox" checked="checked">
</div>

JS

$('#data-attribute-toggle-button').toggleButtons();

Toggle state

JS

$('#my-toggle-button').toggleButtons('toggleState');

Destroy

JS

$('#my-toggle-button').toggleButtons('destroy');

Like this project?

endorse

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.