Reputation: 3041
How to use ON/OFF switches instead of Checkboxes and Radio buttons as shown in image to beautify website design.
Upvotes: 0
Views: 2886
Reputation: 3659
Hope this helps. Check it out!
$(document).ready(function() {
// Switch toggle
$('.Switch').click(function() {
$(this).toggleClass('On').toggleClass('Off');
});
});
Upvotes: 3
Reputation: 21528
If you want to do with your hand, basically you have structure like this:
<div class='button' id='button-0'>
<div class='button-switcher left' id='button-switcher-0'></div>
</div>
And with a script, you animate the inner div in this way:
var switchButton = function() {
$(this).toggleClass('left, right');
var versus = $(this).hasClass('right') ? 1 : -1;
var targetLeft = versus * parseInt($(this).parent().css('width')) / 2;
$(this).animate({
'left': '+=' + targetLeft + "px"
});
}
$('.button-switcher').on('click', switchButton);
Take a look to the working demo.
Upvotes: 1
Reputation: 492
The buttons UI can be designed using css and you can use the toggle method of jquery.
http://api.jqueryui.com/toggle/
After you have written the css for the buttons you just have to add css class and remove css class for the button.
Upvotes: 1