Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Logarithmic Range Slider</h1>
<p class="lead">built with ion.rangeSlider</p>
<div class="number-inputs">
  <input type="number" class="number-input input-min" placeholder="" data-prefix="min" data-value="" min="1" size="12" value="">
  <input type="number" class="number-input input-max" placeholder="" data-prefix="max" data-value="" size="12" value="">
  <input type="number" class="number-input input-from" placeholder="" data-prefix="from" data-value="" min="" max="" size="12" value="">
  <input type="number" class="number-input input-to" placeholder="" data-prefix="to" data-value="" min="" max="" size="12" value="">
</div>

<input type="text" class="range-slider logarithmic">

<h4>output:</h4>
<p class="output"><span class="output-from"></span> — <span class="output-to"></span></p>

              
            
!

CSS

              
                body {
  padding: 10vmin;
  background-color: #232931;
  color: #eee;
}

.number-inputs {
  margin-bottom: 2.5rem; 
}

input[type="number"] {
  -webkit-appearance: textfield; 
  -moz-appearance: textfield;
  appearance: textfield;
  padding: .5em;
  border: 1px solid #666;
  border-radius: .3em;
  outline: none;
  font-size: 1em;
}

.irs {
  max-width: 500px;
  margin-bottom: 3em;
}

.lead {
  font-weight: 600;
  color: #777;
  margin-bottom: 3em;
}

.output {
  font-family: monospace;
  font-size: 1.35em;
}
              
            
!

JS

              
                // My approach to create a logarithmic slider with ion.rangeSlider.

// References:
// https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
// https://gist.github.com/xposedbones/75ebaef3c10060a3ee3b246166caab56
// https://github.com/IonDen/ion.rangeSlider/issues/42
// http://jsfiddle.net/7dbowqfd/5/


// -------------------------------------------
// Extend Number Object with mapping methods
// -------------------------------------------

// maps a value from one range to another
Number.prototype.map = function (inMin, inMax, outMin, outMax) {
  return (this - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}

// remaps a value from a range to a logarithmic scale
Number.prototype.mapLog = function (min, max) {
  const mapped = (this - min) * (Math.log(max) - Math.log(min)) / (max - min) + Math.log(min);
  return Math.exp(mapped);
}

// remaps a value from a range to a logarithmic scale (reversed)
Number.prototype.mapLogRev = function (min, max) {
  return (Math.log(this) - Math.log(min)) * (max - min) / (Math.log(max) - Math.log(min)) + Math.log(min);
  //return (Math.log(this) - Math.log(min)) / (Math.log(max) - Math.log(min)) / (max - min) + min;
}

// -------------------------------------------
// Variables
// -------------------------------------------

let MIN = 10;
let MAX = 100000;
let initFrom  = 100;
let initTo  = 1000;

const $logSlider = $('.range-slider.logarithmic');
const $inputMin = $('.input-min');
const $inputMax = $('.input-max');
const $inputFrom = $('.input-from');
const $inputTo = $('.input-to');

// -------------------------------------------
// Initializing
// -------------------------------------------

// min
$inputMin.attr('placeholder', `min $${MIN.toLocaleString()}`);
$inputMin.attr('data-value', MIN);

// max
$inputMax.attr('placeholder', `max $${MAX.toLocaleString()}`);
$inputMax.attr('data-value', MAX);

// from
$inputFrom.attr('placeholder', `from $${initFrom.toLocaleString()}`);
$inputFrom.attr('data-value', initFrom);
$inputFrom.attr('min', MIN);
$inputFrom.attr('max', MAX);

// to
$inputTo.attr('placeholder', `to $${initTo.toLocaleString()}`);
$inputTo.attr('data-value', initTo);
$inputTo.attr('min', MIN);
$inputTo.attr('max', MAX);

// slider
$logSlider.ionRangeSlider({
  type: 'double',
  grid: true,
  min: mapLogarithmicReverse(MIN),
  max: mapLogarithmicReverse(MAX),
  from: mapLogarithmicReverse(initFrom),
  to: mapLogarithmicReverse(initTo),
  prettify: prettifyLog,
  prefix: '$',
  postfix: '',
  onStart: printSliderData,
  onChange: printSliderData,
  onUpdate: printSliderData
});


// -------------------------------------------
// Helper functions
// -------------------------------------------

function mapLogarithmic(value){
  return Math.ceil(value.mapLog(MIN, MAX));
}

function mapLogarithmicReverse(value){
  return parseFloat(value).mapLogRev(MIN, MAX);
}

function prettifyLog(value) {
  return mapLogarithmic(value).toLocaleString('en-US');
}

// -------------------------------------------
// Event Handler
// -------------------------------------------

// slider
function printSliderData(){
  const prettyFrom = mapLogarithmic($logSlider.data('from'));
  const prettyTo = mapLogarithmic($logSlider.data('to'));

  $('.output-from').text(prettyFrom);
  $('.output-to').text(prettyTo);
}

// number inputs
$('.number-input').on('focus', e => {
  const currentTarget = e.currentTarget;
  currentTarget.value = currentTarget.dataset.value;
});

$('.number-input').on('change', e => {
  const min = $inputMin.val() || $inputMin.attr('data-value');
  const max = $inputMax.val() || $inputMax.attr('data-value');
  const from = $inputFrom.val() || $inputFrom.attr('data-value');
  const to = $inputTo.val() || $inputTo.attr('data-value');
  
  $logSlider.data('ionRangeSlider').update({
    min: mapLogarithmicReverse(min),
    max: mapLogarithmicReverse(max),
    from: mapLogarithmicReverse(from),
    to: mapLogarithmicReverse(to)
  });
});

$('.number-input').on('blur', e => {
  const currentTarget = e.currentTarget;
  const prefix = currentTarget.dataset.prefix;
  const localizedValue = Math.trunc(currentTarget.value).toLocaleString();
  
  currentTarget.placeholder = `${prefix} $${localizedValue}`;
  currentTarget.dataset.value = currentTarget.value;
  currentTarget.value = '';
});






/*
function LogSlider(options) {
   options = options || {};
   this.minpos = options.minpos || 0;
   this.maxpos = options.maxpos || 100;
   this.minlval = Math.log(options.minval || 1);
   this.maxlval = Math.log(options.maxval || 100000);

   this.scale = (this.maxlval - this.minlval) / (this.maxpos - this.minpos);
}

LogSlider.prototype = {
   // Calculate value from a slider position
   value: function(position) {
      return Math.exp((position - this.minpos) * this.scale + this.minlval);
   },
   // Calculate slider position from a value
   position: function(value) {
      return this.minpos + (Math.log(value) - this.minlval) / this.scale;
   }
};
*/
              
            
!
999px

Console