Giter Club home page Giter Club logo

jquery-switch's Introduction

⚠️ This project is no longer maintained! ⚠️

jQuery/Switch

jQuery/Switch is an iOS-inspired slide/toggle widget. It began as an alternative switch for jQuery Mobile, but it also targets desktop browsers as well.

Note: jQuery/Switch is still in heavy development. Features may change without warning!

Usage

jQuery/Switch builds from <select> elements which contain two <option> elements relating to the "on" and "off" states respectively. These can be in any order, but the first <option> will by default be assumed to relate to the "on" state (this can be overridden).

<select>
  <option value="1">On</option>
  <option value="0">Off</option>
</select>

Then, initialize the plugin:

$(document).ready(function() {
  $('select').switchify();
  
  // optionally, override the defaults:
  // $('select').switchify({ on: '1', off: '0' });
});

Features

  • Respects the selected value of the original <select>
  • Supports multiple switches
  • Updates the selected value of the original <select> when the state is updated
  • Listens for the 'change' event on the original <select>
  • Respects the "disabled" attribute
  • Works on both desktop and mobile browsers (see browser support below)
  • Drag or click/tap controls as well as API .on(), .off(), and .toggle()
  • Basic keyboard support (tab-enabled, Enter to toggle)
  • Event driven via the "slide" event

Dependencies

The only dependency is jQuery, which is supported from v1.4.4.

Browser support

Mobile

  • iOS4+ Safari: ok
  • Android Mobile Webkit 533.1: ok
  • Other browsers currently untested

IE

  • IE7 and below: no support
  • IE8: works but lacks CSS support (rounded corners, background size)
  • IE9+: ok

Firefox

  • 3.6 and below: lacks CSS support (background size)
  • 4.0+: ok

Safari

  • 4.0 and below: lacks CSS support (background size)
  • 5.0+: ok

Opera

  • 10+: fine

Chrome

  • 12+: fine

Notes

Due to a webkit bug the markup is fairly complex, which makes custom styling difficult. This will hopefully be improved over time, along with wider browser support (removing the dependency on background-size for one).

Additionally, to improve performance the page offset coordinates of each switch is cached. This means that if the "y" position of a switch changes (ie it is moved horizontally) then the switch may not work correctly. Therefore if you have any actions which may result in your switches changing position, you may need to update the cache by calling the plugin with "update" as the argument:

$('select').switchify('update');

Copyright Rawnet 2011. MIT licence.

jquery-switch's People

Contributors

aquam8 avatar boxofrad avatar boffbowsh avatar

Watchers

James Cloos avatar James W Curnalia 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.