"input box with two spinner controls"
Bootstrap 2.3.2 Snippet by alexk

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/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="row nowrap padding-top-25"> <div class="span4 right-align nowrap margin-top-5">QR-code time out:</div> <div class="span8 bold-text left-align padding_adjust_i"> <div class="inline"> <div class="row"> <div class="col-xs-3 col-xs-offset-3"> <div class="btn-group number-spinner"> <span class="input-prepend data-dwn"> <button class="btn btn-default" data-dir="dwn"><i class="fa_icon icon-minus"></i></button> </span> <input type="text" class="form-control input-box text-center" value="1" min="0" max="180" style="max-width:100px;"> <span class="input-append data-up"> <button class="btn btn-default" data-dir="up"><i class="fa_icon icon-plus"></i></button> </span> </div> <span class="fielderror"><i class="fa_icon icon-minus-sign"></i>numeric input required</span><span class="datatype"><i class="fa_icon icon-info-sign"></i>numeric (number of seconds)</span> <span class="charcount"><i class="fa_icon icon-info-sign"></i>min. 0 - max. 180</span> </div> </div> </div> </div> </div> </div>
.padding-top-25 { padding-top: 25px; } .right-align { text-align:right; } .left-align { text-align: left; } .nowrap { white-space: nowrap; margin: 0 5px 0 5px; } .margin-top-5 { margin-top: 5px; } .fielderror, .datatype, .charcount { display: none; } @media ( max-width: 585px ) { .input-group span.input-group-btn,.input-group input,.input-group button{ display: block; width: 100%; border-radius: 0; margin: 0; } .input-group { position: relative; } .input-group span.data-up{ position: absolute; top: 0; } .input-group span.data-dwn{ position: absolute; bottom: 0; } .form-control.text-center { margin: 34px 0; } .input-group-btn:last-child>.btn, .input-group-btn:last-child>.btn-group{ margin-left:0; } }
$(function() { var action; $(".number-spinner button").mousedown(function () { btn = $(this); input = btn.closest('.number-spinner').find('input'); btn.closest('.number-spinner').find('button').prop("disabled", false); if (btn.attr('data-dir') == 'up') { action = setInterval(function(){ if ( input.attr('max') == undefined || parseInt(input.val()) < parseInt(input.attr('max')) ) { input.val(parseInt(input.val())+1); }else{ btn.prop("disabled", true); clearInterval(action); } }, 50); } else { action = setInterval(function(){ if ( input.attr('min') == undefined || parseInt(input.val()) > parseInt(input.attr('min')) ) { input.val(parseInt(input.val())-1); }else{ btn.prop("disabled", true); clearInterval(action); } }, 50); } }).mouseup(function(){ clearInterval(action); }); });

Related: See More


Questions / Comments:

Good

Rajesh Doot () - 7 years ago - Reply 0