Last active
March 8, 2017 21:03
-
-
Save david-cako/1d285fada9848c1592ac4b39c33e0ac5 to your computer and use it in GitHub Desktop.
Apple-inspired bootstrap slider buttons | demo: https://jsfiddle.net/xxcade2y/1/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.slider { | |
display: inline-block; | |
margin-top: 5px; | |
} | |
.slider-bg { | |
display: inline-block; | |
width: 54px; | |
height: 22px; | |
border-radius: 4px; | |
border-color: rgb(204, 204, 204); | |
background-color: lightgrey; | |
} | |
.slider-bg-active { | |
background-color: #4bd763; | |
} | |
.slider-btn { | |
position: relative; | |
right: 57px; | |
bottom: 8px; | |
border-radius: 4px !important; | |
background-color: #fff !important; | |
margin-top: 1px; | |
border-color: rgb(204, 204, 204) !important; | |
height: 20px; | |
z-index: 2; | |
} | |
.slider-btn:focus { | |
outline: none !important; | |
} | |
.slider-label { | |
position: relative; | |
bottom: 6px; | |
display: inline-block; | |
margin-right: 30px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="slider-label"> | |
<strong>Option:</strong> | |
</div> | |
<div class="slider"> | |
<div class="slider-bg"></div> | |
<button type="button" class="btn btn-default slider-btn"></button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".slider-bg, .slider-btn").click(function(){ | |
var slider = $(this).parent(); | |
console.log(slider); | |
if (slider.children(".slider-bg").hasClass("slider-bg-active")){ | |
slider.children(".slider-bg").removeClass("slider-bg-active"); | |
slider.children(".slider-btn").animate({ | |
right: "57px", | |
}, 200); | |
} else { | |
slider.children(".slider-bg").addClass("slider-bg-active"); | |
slider.children(".slider-btn").animate({ | |
right: "31px", | |
}, 200); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment