Stylish & Animated Slider Widget with jQuery and jQuery UI
File Size: | 10.3 KB |
---|---|
Views Total: | 3257 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |
A super simple jQuery extension that enhances the default jQuery UI slider widget to create a stylish & animated range slider with CSS3 transitions and transforms.
How to use it:
1. Include the necessary jQuery & jQuery UI libraries in your document.
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
2. Include the required jQuery UI CSS (custom bulid) in the head section.
<link rel="stylesheet" href="jquery-ui.css">
3. Include the prefixfree.min.js for CSS3 vendor fixes.
<script src="prefixfree.min.js"></script>
4. Create a slider widget using Html list and input filed.
<div class="slider" id="demo"> <ul role="presentation"> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul> <div></div> <input class="answer" type="hidden"> </div>
5. The required CSS to style the slider widget.
.slider { position: relative; margin: 60px auto 0; padding: 0 10px; width: 370px; height: 20px; border: 0; border-radius: 20px; background-color: #ebebeb; } .slider ul { position: absolute; top: 0; right: 10px; left: 10px; margin: 0; padding: 0; height: 100%; list-style: none; } .slider ul li { position: absolute; top: 50%; left: 0; margin-top: -3px; margin-left: -3px; width: 6px; height: 6px; border-radius: 100%; background-color: #cfcfcf; } .slider ul li:nth-child(1) { left: 0%; } .slider ul li:nth-child(2) { left: 11.11111%; } .slider ul li:nth-child(3) { left: 22.22222%; } .slider ul li:nth-child(4) { left: 33.33333%; } .slider ul li:nth-child(5) { left: 44.44444%; } .slider ul li:nth-child(6) { left: 55.55556%; } .slider ul li:nth-child(7) { left: 66.66667%; } .slider ul li:nth-child(8) { left: 77.77778%; } .slider ul li:nth-child(9) { left: 88.88889%; } .slider ul li:nth-child(10) { left: 100%; } .ui-slider { position: relative; width: 100%; height: 20px; border: 0; border-radius: 20px; background-color: transparent; } .ui-slider .ui-slider-handle { display: block; position: absolute; z-index: 10; top: 50%; margin: 0; width: 30px; height: 30px; border: 8px solid #33b768; border-radius: 100%; background-color: #fff; transform: translate(-50%, -50%); transform: box-shadow ease-out .2s; outline: none; } .ui-slider .ui-slider-handle:focus { box-shadow: 0 0 2px 2px #5EB1F8; } .ui-slider .ui-slider-range { display: none; position: absolute; z-index: 9; } .ui-slider .ui-slider-tooltip { display: block; position: absolute; bottom: 100%; left: 50%; margin-bottom: 10px; margin-left: -13px; padding: 4px 0 9px; width: 26px; height: 40px; color: #fff; font-family: 'Open Sans', sans-serif; font-size: 16px; font-weight: 700; line-height: 25px; text-align: center; background-image: url("slider-arrow.svg"); background-position: -1px -1px; background-repeat: no-re.slider { position: relative; margin: 60px auto 0; padding: 0 10px; width: 370px; height: 20px; border: 0; border-radius: 20px; background-color: #ebebeb; } .slider ul { position: absolute; top: 0; right: 10px; left: 10px; margin: 0; padding: 0; height: 100%; list-style: none; } .slider ul li { position: absolute; top: 50%; left: 0; margin-top: -3px; margin-left: -3px; width: 6px; height: 6px; border-radius: 100%; background-color: #cfcfcf; } .slider ul li:nth-child(1) { left: 0%; } .slider ul li:nth-child(2) { left: 11.11111%; } .slider ul li:nth-child(3) { left: 22.22222%; } .slider ul li:nth-child(4) { left: 33.33333%; } .slider ul li:nth-child(5) { left: 44.44444%; } .slider ul li:nth-child(6) { left: 55.55556%; } .slider ul li:nth-child(7) { left: 66.66667%; } .slider ul li:nth-child(8) { left: 77.77778%; } .slider ul li:nth-child(9) { left: 88.88889%; } .slider ul li:nth-child(10) { left: 100%; } .ui-slider { position: relative; width: 100%; height: 20px; border: 0; border-radius: 20px; background-color: transparent; } .ui-slider .ui-slider-handle { display: block; position: absolute; z-index: 10; top: 50%; margin: 0; width: 30px; height: 30px; border: 8px solid #33b768; border-radius: 100%; background-color: #fff; transform: translate(-50%, -50%); transform: box-shadow ease-out .2s; outline: none; } .ui-slider .ui-slider-handle:focus { box-shadow: 0 0 2px 2px #5EB1F8; } .ui-slider .ui-slider-range { display: none; position: absolute; z-index: 9; } .ui-slider .ui-slider-tooltip { display: block; position: absolute; bottom: 100%; left: 50%; margin-bottom: 10px; margin-left: -13px; padding: 4px 0 9px; width: 26px; height: 40px; color: #fff; font-family: 'Open Sans', sans-serif; font-size: 16px; font-weight: 700; line-height: 25px; text-align: center; background-image: url("slider-arrow.svg"); background-position: -1px -1px; background-repeat: no-repeat; background-size: 28px 42px; transition: opacity ease-out .2s, transform ease-out .1s; transform-origin: 50% 100%; } .ui-slider .ui-slider-tooltip[aria-hidden="true"] { opacity: 0; transform: scale(0); transition-duration: 0s; } .ui-slider .ui-slider-tooltip[aria-hidden="false"] { transform: scale(1); opacity: 1; }peat; background-size: 28px 42px; transition: opacity ease-out .2s, transform ease-out .1s; transform-origin: 50% 100%; } .ui-slider .ui-slider-tooltip[aria-hidden="true"] { opacity: 0; transform: scale(0); transition-duration: 0s; } .ui-slider .ui-slider-tooltip[aria-hidden="false"] { transform: scale(1); opacity: 1; }
6. The Javascript to enable the slider widget.
var tooltipElement = $('<div class="ui-slider-tooltip" aria-hidden="true" />'); var tooltip; var slider = $('.slider > div').slider({ range: "min", value: 7, min: 1, max: 10, step: 1, create: function ( event ) { $( event.target ).find('.ui-slider-handle').append( tooltipElement ); tooltip = $('.ui-slider-tooltip'); }, change: function ( event, ui ) { var input = $( event.target ).parent().find('input.answer'); input.val( ui.value ); window.tooltip.text( ui.value ); window.tooltip.attr('aria-hidden', 'false'); }, slide: function ( event, ui ) { window.tooltip.attr('aria-hidden', 'true'); } });
This awesome jQuery plugin is developed by Michiel. For more Advanced Usages, please check the demo page or visit the official website.