cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Untitled

A Pen By Captain Anonymous

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <p>Tips : You could use the mouse wheel to increase/decrease the value when the input textbox has the 'focus'</p>

<div style="width:150px">
<div class="stepper" id="stepper_1">
  <div class="stepper-progress"></div>
  <input type="text" class="stepper-number" min="10" max="90" value="50">
</div>

<br>
  
<div class="stepper" id="stepper_2">
  <div class="stepper-progress"></div>
  <input type="text" class="stepper-number" min="0" max="500">
</div> 
  
<br>
  
<div class="stepper" id="stepper_3">
  <div class="stepper-progress"></div>
  <input type="text" class="stepper-number">
</div> 

<br>
  
<div class="stepper" id="stepper_4">
  <div class="stepper-progress"></div>
  <input type="text" class="stepper-number" unit="px" step="5">
</div> 

<br>
  
<div class="stepper" id="stepper_5">
  <div class="stepper-progress"></div>
  <input type="text" class="stepper-number" unit="" min="1" max="10" decimals="2" value="2.55" step="0.1">
</div> 
  
</div>
            
          
!
            
              * {
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

div {
  display: block;
}

.stepper {
  position: relative;
  width: 100%;
  height: 30px;
  background: #4e4e4e;
  border: 1px solid #292929;
  cursor: col-resize;
}

.stepper .stepper-number:focus {
  outline: 1px solid #1baee1;
  //cursor: text
}

.stepper-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: rgba(255, 255, 255, 0.2);
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
  -webkit-transition: background-color 0.1s linear;
  transition: background-color 0.1s linear;
}

.stepper-number {
  position: relative;
  width: 100%;
  height: 28px;
  line-height: 28px;
  padding: 0 6px;
  color: #fff;
  background: transparent;
  border: 0;
  outline: 0;
  outline-offset: 0;
  cursor: col-resize;
  z-index: 2;
}

.stepper.is-changing .stepper-progress {
  background-color: #1baee1;
}

.stepper.is-scrubbing {
  background: rgba(255, 255, 255, 0.8)
}
            
          
!
            
              // jquery.stepper.js
// https://github.com/ncou/jquery.stepper.basic
// ------------------------------------------------------
// Author: NCOU
//
// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
(function($, window, document, undefined) {
  "use strict";
  var pluginName = "stepper",
    defaults = {
      selectorProgressBar: ".stepper-progress",
      selectorInputNumber: ".stepper-number",
      classNameChanging: "is-changing",
      value: "",
      decimals: 0,
      min: 0,
      max: 100,
      step: 1,
      unit: "%"
    };

  // The actual plugin constructor
  function Plugin(element, options) {
    this.element = element;

    this.settings = $.extend({}, defaults, options);

    this._defaults = defaults;
    this._name = pluginName;

    this.init();
  }

  // Avoid Plugin.prototype conflicts
  $.extend(Plugin.prototype, {
    init: function() {
      // local variable
      this._curDown = false;
      this._mouseDownX = 0;
      this._mouseDownValue = 0;

      // Cache elements
      this.$el = $(this.element);
      this.$input = this.$el.find(this.settings.selectorInputNumber);
      this.$progress = this.$el.find(this.settings.selectorProgressBar);

      // init values
      this.decimals = this.$input.attr("decimals") || this.settings.decimals;
      this.min = this.$input.attr("min") || this.settings.min;
      this.max = this.$input.attr("max") || this.settings.max;
      this.step = this.$input.attr("step") || this.settings.step;
      this.unit = this.$input[0].hasAttribute("unit") ? this.$input.attr("unit") : this.settings.unit;

      this.value =
        this.$input.val() ||
        (this.settings.value !== ''
          ? this.settings.value
          : this.max);

      this.setValue(this.value);

      // Bind events
      this.$input.on("keydown", this.onKeyPress.bind(this));
      this.$input.on("blur", this.onBlur.bind(this));
      this.$input.on("paste input", this.onChange.bind(this));
      this.$el.on("mousedown touchstart", this.onMouseDown.bind(this));
      this.$el.on("wheel", this.onMouseWheel.bind(this));
      $(document).on("mouseup touchend", this.onMouseUp.bind(this));
      $(document).on("mousemove touchmove", this.onMouseMove.bind(this));
    },

    onMouseDown: function(e) {
      this._mouseDownX = e.clientX || e.originalEvent.touches[0].clientX;
      this._mouseDownValue = this.getValue();

      this._changeStart();
    },

    onMouseUp: function(e) {
      this._changeEnd();
    },

    onMouseMove: function(e) {
      if (this._curDown === true) {
        var t =
          (e.clientX || e.originalEvent.touches[0].clientX) - this._mouseDownX;
        this.setValue(this._mouseDownValue + t * this.step);
      }
    },

    onMouseWheel: function(e) {
      // prevent [wheel increase and mousemove increase] and [wheel increase] if the input field is not focused
      if (this._curDown === false && this.$input.is(":focus")) {
        e.preventDefault();
        // delta is 1 if scroll up, or -1 if scroll down
        var d = e.originalEvent.deltaY < 0 ? 1 : -1;
        this.setValue(this.getValue() + d * this.step);
      }
    },

    onChange: function(e) {
      this._updateProgress(this.getValue());
    },

    onBlur: function(e) {
      this._changeEnd();
      this.setValue(this.getValue());
    },

    onKeyPress: function(e) {
      // exit the input field if key pressed is 'Enter'
      if (e.keyCode === 13) {
        this.$input.blur();
      }
    },

    getValue: function() {
      return parseFloat(this.$input.val()) || 0;
    },

    setValue: function(amount) {
      var value;

      value = Math.max(Math.min(amount, this.max), this.min);
      value = this._roundValue(value);

      var n = value;
      n = n.toFixed(this.decimals);

      n += this.unit;
      this.$input.val(n);

      this._updateProgress(value);
    },

    _updateProgress: function(v) {
      var r = this._valueToPercent(v) / 100;
      this.$progress.css("transform", "scaleX(" + r + ")");

      this.$input.trigger("change");
    },

    _percentToValue: function(v) {
      return this.min + v / 100 * (this.max - this.min);
    },

    _valueToPercent: function(v) {
      var t = (v - this.min) / (this.max - this.min) * 100;
      return Math.max(Math.min(t, 100), 0);
    },

    _roundValue: function(v) {
      var maxDecimals = 2;

      var t = Math.pow(10, maxDecimals);
      return Math.round(v * t) / t;
    },

    _changeStart: function() {
      this._curDown = true;
      this.$el.addClass(this.settings.classNameChanging);
    },

    _changeEnd: function() {
      this._curDown = false;
      this.$el.removeClass(this.settings.classNameChanging);
    }
  });

  // A lightweight plugin wrapper around the constructor, preventing against multiple instantiations
  $.fn[pluginName] = function(options) {
    return this.each(function() {
      if (!$.data(this, "plugin-" + pluginName)) {
        $.data(this, "plugin-" + pluginName, new Plugin(this, options));
      }
    });
  };
})(jQuery, window, document);

$('#stepper_1').stepper();
$('#stepper_2').stepper();
$('#stepper_3').stepper({
  unit: 's',
  value: 20,
  min: 0,
  max: 300,
  step: 10
});
$('#stepper_4').stepper();
$('#stepper_5').stepper();
            
          
!
999px
Loading ..................

Console