javascript - Change tooltip with progress slider -
i using script change colored slider. want add text/tooltip progress drag 0% 100% . how can add this? please can me this? fiddle
function getthecolor(colorval) { var thecolor = ""; if (colorval < 50) { myred = 255; mygreen = parseint(((colorval * 2) * 255) / 100); } else { myred = parseint(((100 - colorval) * 2) * 255 / 100); mygreen = 255; } thecolor = "rgb(" + myred + "," + mygreen + ",0)"; return (thecolor); } function refreshswatch() { var coloredslider = $("#coloredslider").slider("value"), mycolor = getthecolor(coloredslider); $("#coloredslider .ui-slider-range").css("background-color", mycolor); $("#coloredslider .ui-state-default, .ui-widget-content .ui-state-default").css("background-color", mycolor); } $(function() { $("#coloredslider").slider({ orientation: "horizontal", range: "min", max: 100, value: 0, slide: refreshswatch, change: refreshswatch }); });
body { font-family: arial, helvetica, sans-serif; } #coloredslider { float: left; clear: left; width: 600px; margin: 15px; } #coloredslider .ui-slider-range { background: #ff0000; } #coloredslider .ui-state-default, .ui-widget-content .ui-state-default { background: none; background-color: #fff; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <p>a colored jquery ui slider</p> <div id="coloredslider"></div>
here's trick..
var initialvalue = 0; var slidertooltip = function(event, ui) { var curvalue = ui.value || initialvalue; var tooltip = '<div class="tooltip"><div class="tooltip-inner">' + curvalue + '</div><div class="tooltip-arrow"></div></div>'; $('.ui-slider-handle').html(tooltip); } $("#coloredslider").slider({ value: initialvalue, min: 0, max: 100, step: 20, create: slidertooltip, slide: slidertooltip });
body { font-family: arial, helvetica, sans-serif; } #coloredslider { float: left; clear: left; width: 600px; margin: 15px; } #coloredslider .ui-slider-range { background: #ff0000; } #coloredslider .ui-state-default, .ui-widget-content .ui-state-default { background: none; background-color: #fff; } .tooltip { position: absolute; z-index: 1020; display: block; padding: 5px; font-size: 11px; visibility: visible; margin-top: -2px; bottom:120%; margin-left: -0.6em; } .tooltip .tooltip-arrow { bottom: 0; left: 50%; margin-left: -5px; border-top: 5px solid #000000; border-right: 5px solid transparent; border-left: 5px solid transparent; position: absolute; width: 0; height: 0; } .tooltip-inner { max-width: 200px; padding: 3px 8px; color: #ffffff; text-align: center; text-decoration: none; background-color: #000000; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <p>a colored jquery ui slider</p> <div id="coloredslider"></div>
Comments
Post a Comment