SlideOn

Fork me on GitHub

Description


Slideon is a simple component which creates beautiful slide switches, by converting checkboxes, with zero latency and easy integration.

Why slideon over other components


No latency - while integrating many other similar components, you will see a minor latency(checkbox turning to switch) if your project is huge but not in slideon.

Easy integration - just add some classes to your checkbox.

Different styles - just add some classes for different sizes, shapes and colors.

Events and actions - you can trigger events and actions just like how you do with a normal checkbox.

Light weight - the component is very much lighter.

Faster - the processing of component is faster.

Installation


CDN

Add the following cdn to your web page.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/shaheenhyderk/slideon@1.0.2/slideon.css"/> <script src="https://cdn.jsdelivr.net/gh/shaheenhyderk/slideon@1.0.2/slideon.js"></script>

Standalone

Download slideon and just add the script file and css file to your website.

<link rel="stylesheet" href="slideon.css"/> <script src="slideon.js"></script>

Integration


You can integrate it in 2 methods. Method 1 is easy, while method 2 is fast.

Method 1

Add 2 classes, slideon and slideon-auto to your checkbox and call the load function as shown below. This is the simplest way to integrate but there is a chance of a minute latency which won't be noticeable as there are some js processing.

<input type="checkbox" class="slideon slideon-auto" checked> <script>   var slideon = new Slideon()   slideon.load() </script>

Method 2

Wrap your checkbox with a label which has a class slideon in it and add a span sibling to your checkbox with a class slideon-slider. This is comparitively a bit more lengthy to integrate, but the latency will be zero as there won't be any js processing.

<label class="slideon">   <input type="checkbox" checked>   <span class="slideon-slider"></span> </label>

Load Dynamic Checkboxes


If you are using the method 1 for integration that is with slideon-auto, the you should call the load function while adding checkbxes in the run time.

For method 2 you don't have to do anything extra while adding checkbxes in the run time.

Styles


Slideon currently supports different colors, sizes and shapes. You can use combinations of all the styles shown below.

Colors

Currently slideon supports 7 colors. It follows color standards of bootstrap colors.

  • slideon-primary
  • slideon-secondary
  • slideon-success
  • slideon-warning
  • slideon-info
  • slideon-dark

<input type="checkbox" class="slideon slideon-auto slideon-primary" checked> <input type="checkbox" class="slideon slideon-auto slideon-secondary" checked> <input type="checkbox" class="slideon slideon-auto slideon-success" checked> <input type="checkbox" class="slideon slideon-auto slideon-danger" checked> <input type="checkbox" class="slideon slideon-auto slideon-warning" checked> <input type="checkbox" class="slideon slideon-auto slideon-info" checked> <input type="checkbox" class="slideon slideon-auto slideon-dark" checked>

Sizes

Currently slideon supports 5 sizes.

  • slideon-xs
  • slideon-sm
  • slideon-md
  • slideon-lg
  • slideon-xl

<input type="checkbox" class="slideon slideon-auto slideon-xs" checked> <input type="checkbox" class="slideon slideon-auto slideon-sm" checked> <input type="checkbox" class="slideon slideon-auto slideon-md" checked> <input type="checkbox" class="slideon slideon-auto slideon-lg" checked> <input type="checkbox" class="slideon slideon-auto slideon-xl" checked>

Paddings

Currently slideon supports 3 levels of padding for the switch.

  • slideon-p0
  • slideon-p1
  • slideon-p2

<input type="checkbox" class="slideon slideon-auto slideon-p0" checked> <input type="checkbox" class="slideon slideon-auto slideon-p1" checked> <input type="checkbox" class="slideon slideon-auto slideon-p2" checked>

Shapes

Currently slideon supports 2 shapes.

  • slideon-round
  • slideon-square

<input type="checkbox" class="slideon slideon-auto slideon-round" checked> <input type="checkbox" class="slideon slideon-auto slideon-square" checked>

Disabled

Make slideon button disabled just by adding disabled to your input.

<input type="checkbox" class="slideon slideon-auto" disabled> <input type="checkbox" class="slideon slideon-auto" checked disabled>

Actions and events


All the events and actions are done with js just like how you handle a normal check box.

License


Copyright 2022 Shaheen Hyder


Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:


The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.


THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.