Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 198581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:56:59+00:00 2026-05-11T16:56:59+00:00

I have a slider with values ranging from 0 to 100. I want to

  • 0

I have a slider with values ranging from 0 to 100.

I want to map them to a range from 100 to 10,000,000.

I’ve seen some functions scattered around the net but they’re all in C++.
I need it in Javascript.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:56:59+00:00Added an answer on May 11, 2026 at 4:56 pm

    You can use a function like this:

    function logslider(position) {
      // position will be between 0 and 100
      var minp = 0;
      var maxp = 100;
    
      // The result should be between 100 an 10000000
      var minv = Math.log(100);
      var maxv = Math.log(10000000);
    
      // calculate adjustment factor
      var scale = (maxv-minv) / (maxp-minp);
    
      return Math.exp(minv + scale*(position-minp));
    }
    

    The resulting values match a logarithmic scale:

    js> logslider(0);
    100.00000000000004
    js> logslider(10);
    316.22776601683825
    js> logslider(20);
    1000.0000000000007
    js> logslider(40);
    10000.00000000001
    js> logslider(60);
    100000.0000000002
    js> logslider(100);
    10000000.000000006
    

    The reverse function would, with the same definitions for minp, maxp, minv, maxv and scale, calculate a slider position from a value like this:

    function logposition(value) {
       // set minv, ... like above
       // ...
       return (Math.log(value)-minv) / scale + minp;
    }
    

    All together, wrapped in a class and as a functional code snippet, it would look like this:

    // Generic class:
    
    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;
       }
    };
    
    
    // Usage:
    
    var logsl = new LogSlider({maxpos: 20, minval: 100, maxval: 10000000});
    
    $('#slider').on('change', function() {
       var val = logsl.value(+$(this).val());
       $('#value').val(val.toFixed(0));
    });
    
    $('#value').on('keyup', function() {
       var pos = logsl.position(+$(this).val());
       $('#slider').val(pos);
    });
    
    $('#value').val("1000").trigger("keyup");
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    Input value or use slider:
    <input id="value" />
    <input id="slider" type="range" min="0" max="20" />
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a range slider and I want it to display values from a
I have a slider that returns values from 0.0f to 1.0f. I want to
I want to create a slider, with values from 0 to 100 that I
I'd like to have a slider (lets say values from 0 to 4) and
I want to display a Slider ranging from 0.5 to 1.5 with only one
I have one slider to select time range, from 1 (,2,3,..) day (,weeks,months,..) ago
I have 4 values in UISlider . I want that when the slider value
I have a slider in jQuery UI where I have some predefined values that
I have a slider with values 1 - 5. it updates a hidden input
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.