"Fuel Cost Calculator"
Bootstrap 3.3.0 Snippet by ostrong

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="price-box"> <h3 align="center"><strong>Move the sliders below to see you much you'll save:</strong></h3> <div class="row"> <div class="col-sm-6"> <form class="form-horizontal form-pricing" role="form"> <div class="price-slider"> <h4 class="great">How many cigarettes in a packet?</h4> <div class="col-sm-12"> <div id="Pktslider"></div> </div> </div> <div class="price-slider"> <h4 class="great">How much does the packet cost you?</h4> <div class="col-sm-12"> <div id="PriceSlider"></div> </div> </div> <div class="price-slider"> <h4 class="great">How many cigarettes do you smoke per day?</h4> <div class="col-sm-12"> <div id="SmkDaySlider"></div> </div> </div> </div> <div class="col-sm-6"> <div class="price-form"> <div class="form-group"> <div class="row"> <div class="col-sm-6"> <label class="control-label">Cost per Month:</label> </div> <div class="col-sm-6"> <input type="hidden" id="total" class="form-control"> <p class="price lead" type="text" id="total-label" disabled="disabled" style=""></p> </div> </div> </div> <div class="form-group"> <div class="row"> <div class="col-sm-6"> <label class="control-label">Cost per Year:</label> </div> <div class="col-sm-6"> <input type="hidden" id="totalYr" class="form-control"> <p class="price lead" type="text" id="totalYr-label" disabled="disabled" style=""></p> </div> </div> </div> </div> </form> </div> </div> </div> </div> <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
body { padding-top: 60px; } .price-box { margin: 0 auto; background: #E9E9E9; border-radius: 10px; padding: 40px 15px; /*width: 500px;*/ } .ui-widget-content { border: 1px solid #bdc3c7; background: #e1e1e1; color: #222222; margin-top: 4px; } .ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 7.2em; height: 2.7em; cursor: default; margin: 0 -40px auto !important; text-align: center; line-height: 30px; color: #FFFFFF; font-size: 12px; } .ui-slider .ui-slider-handle .glyphicon { color: #FFFFFF; margin: 0 1px; font-size: 11px; opacity: 0.7; } .ui-corner-all { border-radius: 20px; } .ui-slider-horizontal .ui-slider-handle { top: -.9em; } .ui-state-default, .ui-widget-content .ui-state-default { border: 1px solid #f9f9f9; background: #3498db; } .ui-slider-horizontal .ui-slider-handle { margin-left: -0.5em; } .ui-slider .ui-slider-handle { cursor: pointer; } .ui-slider a, .ui-slider a:focus { cursor: pointer; outline: none; } .price, .lead p { font-weight: 600; font-size: 32px; display: inline-block; line-height: 60px; border:0; width: 245px; } h4.great { margin: 0 0 25px 0; padding: 7px 15px; font-size: 18px; font-weight: 600; } .total { border-bottom: 1px solid #7f8c8d; /*display: inline; padding: 10px 5px;*/ position: relative; padding-bottom: 20px; } .total:before { content: ""; display: inline; position: absolute; left: 0; bottom: 5px; width: 100%; height: 3px; background: #7f8c8d; opacity: 0.5; } .price-slider { margin-bottom: 70px; } .price-slider span { font-weight: 200; display: inline-block; color: #7f8c8d; font-size: 13px; } .form-pricing { background: #ffffff; padding: 20px; border-radius: 4px; } .price-form { background: #ffffff; margin-bottom: 10px; padding: 20px; border: 1px solid #eeeeee; border-radius: 4px; /*-moz-box-shadow: 0 5px 5px 0 #ccc; -webkit-box-shadow: 0 5px 5px 0 #ccc; box-shadow: 0 5px 5px 0 #ccc;*/ } .form-group { margin-bottom: 0; } .form-group span.price { font-weight: 200; display: inline-block; color: #7f8c8d; font-size: 14px; } .help-text { display: block; margin-top: -10px; margin-bottom: 10px; color: #737373; /*position: absolute;*/ /*margin-left: 20px;*/ font-weight: 200; /*text-align: right;*/ width: 188px; } .price-form label { font-weight: 200; font-size: 21px; } img.payment { display: block; margin-left: auto; margin-right: auto } .ui-slider-range-min { background: #2980b9; } .active-month, .active-term { background: #3276b1; } /* HR */ hr.style { margin-top: 0; border: 0; border-bottom: 1px dashed #ccc; background: #999; }
$(document).ready(function() { $("#Pktslider").slider({ animate: true, value:0, min: 0, max: 50, step: 5, slide: function(event, ui) { update(1,ui.value); //changed } }); $("#PriceSlider").slider({ animate: true, value:0, min: 0, max: 50, step: 1, slide: function(event, ui) { update(2,ui.value); //changed } }); $("#SmkDaySlider").slider({ animate: true, value:0, min: 0, max: 100, step: 1, slide: function(event, ui) { update(3,ui.value); //changed } }); //Added, set initial value. $("#Pktslider").val(0); $("#PriceSlider").val(0); $("#SmkDaySlider").val(0); $("#amount-label").text(0); update(); }); //changed. now with parameter function update(slider,val) { //changed. Now, directly take value from ui.value. if not set (initial, will use current value.) var $pktamount = slider == 1?val:$("#Pktslider").val(); var $pktCost = slider == 2?val:$("#PriceSlider").val(); var $smkDaily = slider == 3?val:$("#SmkDaySlider").val(); /* commented $amount = $( "#slider" ).slider( "value" ); $duration = $( "#slider2" ).slider( "value" ); */ //"$" + var Month = ((($pktCost / $pktamount) * $smkDaily) * 30).toFixed(2); //calculation here var Year = ((($pktCost / $pktamount) * $smkDaily) * 365).toFixed(2); if(isNaN(Month)){ $total= "$0.00" $totalYr= "$0.00" }else{ $total= "$" + Month $totalYr= "$" + Year } $( "#Pktslider" ).val($pktamount); $( "#amount-label" ).text($pktamount); $( "#PriceSlider" ).val($pktCost); $( "#duration-label" ).text($pktCost); $( "#total" ).val($total); $( "#total-label" ).text($total); $( "#totalYr-label" ).text($totalYr); $('#Pktslider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$pktamount+' <span class="glyphicon glyphicon-chevron-right"></span></label>'); $('#PriceSlider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> $'+$pktCost+' <span class="glyphicon glyphicon-chevron-right"></span></label>'); $('#SmkDaySlider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$smkDaily+' <span class="glyphicon glyphicon-chevron-right"></span></label>'); }

Related: See More


Questions / Comments: