Giter Club home page Giter Club logo

rangeslider.js's Introduction

rangeslider.js

Build Status npm version jsDelivr Hits npm downloads

Simple, small and fast jQuery polyfill for the HTML5 <input type="range"> slider element.

Check out the examples.

  • Touchscreen friendly
  • Recalculates onresize so suitable for use within responsive designs
  • Small and fast
  • Supports all major browsers including IE8+

Install

📦: npm install --save rangeslider.js

Further Reading

Related

License

MIT © André Ruffert

rangeslider.js Gitter JS.ORG

rangeslider.js's People

Contributors

andreruffert avatar austinpray avatar avindra avatar boekkooi avatar buunguyen avatar gitter-badger avatar gwarnants avatar jugglinmike avatar lukasdrgon avatar mwean avatar ocombe avatar peterdavehello avatar satazor avatar tomru avatar yahkob avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rangeslider.js's Issues

IE8 not recognising Min and Max values

Webkit and IE9+ when the min and max attributes are changed via script the slider "respects" the new values, but in IE8 it doesn't seem to have effect and it considers only values which the slider was initiated with.

Plugin name

Isn't this plugin a "slider", and not a "range slider"? This slider only has one point to move, which obviously does not classify as a "range." The name is confusing because I searched Google and found this plugin, but it doesn't allow for a "range" of values in slider form. Shouldn't the name be changed?

Impossible to set max='0'

It's impossible to set a max to 0 for now

this.max        = parseFloat(this.$element[0].getAttribute('max')) || 100;

0 is false, so it goes to 100 by default.

Clicking bar should step the handle

Instead of landing directly to the click point, it should step towards it. Which is default behaviour for sliders.

For instance, if the handle is at 0% and user clicks somewhere 100%, new handle position should be 10%, if stepping is 10.

[Error] TypeError: 'undefined' is not an object (evaluating 'e.originalEvent.touches[0].clientX')

I get this error when using the slider on ios 5-7 (it does slide normally but once i lift my finger the error appears ).

Do to the error the callbacks don't fire (onside, onSlideEnd.. etc)

Here is what i got from the remote debug log on safari (demo has the same issue)

[[Warning] Invalid CSS property declaration at: ; (style.css, line 2406)
[Error] TypeError: 'undefined' is not an object (evaluating 'e.originalEvent.touches[0].clientX')
getRelativePosition (rangeslider.js, line 249)
handleEnd (rangeslider.js, line 206)
e (jquery.js, line 2)
dispatch (jquery.js, line 3)
handle (jquery.js, line 3)

Can we have one slider and two ranges, min max ?

Hi,
I am sorry if this place is for issues, but can't find another place where to ask a question, I noticed in the demo that the slider have only one value,
My question is

  1. It is possible to have two values in the slider ? how to read them in an text input ?

2)Is this working when javascript is disabled ?
Thanks

handleEnd oddity

Are there any issues around handleEnd on touch devices? I'm finding rangeslider works fine on a mouse/desktop but the same code has problems on iPad and Android tablets. It seems handleEnd only calls my onSlideEnd func on every other handleEnd event. Looks like it barfs at the call to getRelativePosition. Any ideas?

JavaScript error on mobile: Uncaught TypeError: Cannot read property 'clientX' of undefined

Browser: Chrome (Mobile), Chrome (Desktop with Galaxy S4 Emulator turned on)

Steps to reproduce:

  1. Open Chrome Developer Tools (CTRL+Shift+C)
  2. At the bottom near Console click on Emulation
  3. From the dropdown select "Samsung Galaxy S4" and click "Emulate"
  4. Go to http://andreruffert.github.io/rangeslider.js/
  5. On the page drag the slider to the left

Expected:
No javascript errors in the console

Actual:
Uncaught TypeError: Cannot read property 'clientX' of undefined rangeslider.js:249
Plugin.getRelativePosition rangeslider.js:249
Plugin.handleEnd rangeslider.js:206
m.extend.proxy.m.isFunction.e jquery.min.js:2
m.event.dispatch jquery.min.js:3
m.event.add.r.handle jquery.min.js:3

In the code this is at

Plugin.prototype.getRelativePosition = function(node, e) {
return (e.pageX || e.originalEvent.clientX || e.originalEvent.touches[0].clientX || e.currentPoint.x) - this.getPositionFromNode(node);
};

When trying to access e.originalEvent.touches[0]

This causes my app not to work on mobile which is pretty unfortunate because your slider is awesome.

prevent snapping?

Is there anyway to prevent it from 'snapping', instead just having smooth sliding from 0 - 100?

Thanks

Demo site is broken

On both firefox and chrome, the demo site is broken because of this:

Blocked loading mixed active content "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"

[Learn More]

Floating point error ?

I have a value of 5.3 in my <input type="range" step="0.1" max="10" value="5.3" but the rangeslider sets itself to 5.4 instead.

Also, onSlide: function(position, value) { returns 5.4 as value for that first run (without having touched the slider - just initial values ...

Maybe related:
When step value is set to 0.1 (like I have in code above) when sliding I get values of 3.79 and 3.90 (in stead of 3.8 and 3.9)

Thanks for a nice plugin. Would be awesome if these "bugs" can be solved.
Tested this on Safari and Chrome (on mac)

if range input is hidden, initialization fails

If the input is inside a hidden element (example: a bootstrap tab), then the initialization wont get the widths and the component will not behave the way it should.
The workaround is to initialize only when the input becomes visible, but it would be nice if this worked seamlessly

Only works with touch for touchscreen laptops

Hey there,

So I discovered a weird bug related to those hybrid touchscreen laptops floating around there on the market. Issue is verified to exist even on: http://andreruffert.github.io/rangeslider.js/

If you are using a laptop with a touchscreen, you cannot modify the slider with anything other than touch. You can touch the dial and move it like normal, but cannot use the mouse to modify the dial.

This looks like the culprit in the source:

function isTouchScreen() {
        var bool = false,
            DocumentTouch = DocumentTouch || {};
        if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
            bool = true;
        }
        return bool;
    }

    var pluginName = 'rangeslider',
        pluginInstances = [],
        touchevents = isTouchScreen(),
        inputrange = supportsRange(),
        defaults = {
            polyfill: true,
            rangeClass: 'rangeslider',
            fillClass: 'rangeslider__fill',
            handleClass: 'rangeslider__handle',
            startEvent: ((!touchevents) ? 'mousedown' : 'touchstart') + '.' + pluginName,
            moveEvent: ((!touchevents) ? 'mousemove' : 'touchmove') + '.' + pluginName,
            endEvent: ((!touchevents) ? 'mouseup' : 'touchend') + '.' + pluginName
        };

Can the plugin work with both touchstart AND mouse events?

Dynamically Updating Min / Max Values

I can dynamically change the value of an input, but not the min or max attributes and have it adjust the slider? Thoughts on how this could be achieved?

Use Case: I'm making a media player with a timeline that changes from video to video in a playlist. The total duration (the max) changes between videos.

Vertical range?

This looks like a great polyfill/plugin but I need to use it for vertical range's too (volume control in a video player. Is this something you're considering?

Changelog

I couldn't find a changelog.
Is there one?

Thank you

Display as many output as slider controls (Error added)

Hi,

You did a great job for rangeslider.js. Thanks you so much for that.
I have a question:

  1. How can I display each slider with its own output in same page
  2. How can I pass string value instead of int e.g. it's displaying value="50" as 50 in output screen but when I do value="XYZ", its telling undefined

Can you please help out?

Thanks with best regards,
Ripal

Two handles for range

To set starting and ending point, two handles are necessary. If you plan to implement this, please let handles to move both ways when overlapped. Many sliders fail to do that.

Touch Screen PC (IE Only)

Hi,

The slider control doesn't seem to be working on touch screen pc (IE browser), unable to slide, it seems to be fine on other browsers on the same pc. maybe we need to extend the rangeslider to support the MSTouchEvents if mspointerEnabled is true

If container is hidden on .rangeslider() call on ie9, slider can not be grabbed

When using something like this on IE9;

#zoomer {
    display: none;
    position: absolute;
}
#zoomer.show {
    display: block;
    position: static;
}

<div id='zoomer'>
    <input type='range' min='1' max='3' step='0.05' value='1'>
</div>

<!--[if lte IE 9 ]>
<script src="js/rangeslider.min.js"></script>
<script>
    jQuery(document).ready(function($){
        $('#zoomer input').rangeslider({polyfill: false});
    )};
</script>
<![endif]-->

And then later some JS adding show class to #zoomer, the #zoomer becomes visable, the input is hidden and the correct rangeslider elements are created, however rangeslider__handle is not able to be moved.

To fix this make the element shown, call rangeslider() on it, and then hide it with some JS on load

.ie9 #zoomer {
    display: block;
    position: static;
}

<!--[if lte IE 9 ]>
    <script src="js/rangeslider.min.js"></script>
    <script>
        jQuery(document).ready(function($){
            $('#zoomer input').rangeslider({polyfill: false});
            if($('html').hasClass('ie9')) {
                $('#zoomer').css({
                    'display': 'none',
                    'position': 'absolute'
                });
            }
        });
    </script>
<![endif]-->

Display None to Display is broken

Hi Andre,

Once we apply style display none to div which is containing output and input range and then using JQuery if we remove display none, slider is not working as per expectation.

Can you please suggest solution for this?
Thanks in advance.

Regards,
Ripal

Removes keyboard support

The slider control has keyboard arrow-key support, probably some other keys and input events too. The plugin removes that support, making it kinda hard for people who are handicapped and not nearly as fast with a mouse.

issue multiple rangeslide initialized bye jquery.

I am trying to initialized two range slider by jquery . and updating width of the slider. it dosn't wor but when i press f12 or inspect element it's automatically correct and working . i am bit confuse is that happening.

value="0" is ignored, sets to half of range

You can't default a slider to 0, it sets to half of the range.

This seems to be the problem:

this.value  = parseFloat(this.$element[0].value) || this.min + (this.max-this.min)/2;

Something like this might do the trick:

var value = parseFloat(this.$element[0].value);
this.value      = !isNaN(value) ? value : this.min + (this.max-this.min)/2;

IE11

This slider seems to work well in non-IE versions, but in IE11, the display is very unpredictable - sometimes it works and sometimes it displays the slider too far wide. See screenshot attached.
You can see in the screenshot how crazy it appears. If I refresh the page, it often clears up, but that's not a solution.
This page has about 30 sliders on it. Each has a value preset in the "value" parameter of the element. I welcome solutions because I would love to continue to use this slider, but it's only working about half the time the page loads in IE11. If I refresh the page in IE11, it will correct itself and display correctly about 75% of the time. This site also uses the Bootstrap 3.0 CSS framework. Looks and works great in Firefox!

capture selection-20141023-105033-1
The second screenshot shows the correct display.
capture selection-20141023-105147-1

display:none dimensions

To reproduce:

  1. create a slider
  2. note the value
  3. set the slider element to display: none
  4. resize the window
  5. set the slider element to display: block

Expected behavior: the slider retains its previous value and is usable.

Observed behavior: the slider value changes to 50% of the slider range. The slider becomes unresponsive.

Workaround: visibility: hidden; height: 0; on the slider element works fine, but is not a direct replacement

Position when body != window

It may have been a poor choice when I elected to give my body a width less than that of the window, but Its too late to turn back now.

It seems that range slider is calculating mouse position relative to the window but is positioning the handle relative to the body, meaning whenever my window is wider than 1190 in this case, the output value (and handle placement) are off by the difference between my body element edge and the wind edge.

I tried changing this.$window = $(window); to this.$window = $("body"); - but no luck there.

Any guesses?

Snapping should be enabled when step is == 1

The bug was introduced in #33.

Firefox and chrome implementation snap to each steps even when the step is "1". You can reproduce the issue by creating an input like this <input type="range" min="0" max="5" step="1" value="2">. When you add rangeslider.js it stop snapping.

Here is a simple jsfiddle which shows the issue: http://jsfiddle.net/JdkjF/

For reference: http://www.w3.org/TR/2012/WD-html5-20121025/common-input-element-attributes.html#attr-input-step

min != 0 doesn't work.

Hi André,

I have an other issue. In our case min is 50 and not 0.
"Uncaught TypeError: Cannot read property '0' of undefined"

Thank you :-)

cheers,

e.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.