문제

I'm trying to fix a discrepancy between oldVal and newVal in a 'range slider' and 'number spinner input' both binded to each other. I noticed a bug where the oldVal and newVal had a large discrepancy. I would expect a difference of 1 or maybe 5 as the step is set to 5.

This bug becomes noticable when I bind the slider and spinner, but looking at the console, really binding them just makes the underlying problem with newVal and oldVal visible: the further we drag the slider to the right, the greater the discrepancy.

Here is what I tried to bind the slider & spinner:

var spinnerVal = newVal; 
var newCss = spinnerVal / 100 + "%";
document.querySelector('.range-quantity').style.width = newCss;
document.querySelector('.range-handle').style.left = newCss;

slider & spinner bound

http://jsfiddle.net/PaulOD/PpCC4/4/

I'm not sure if this is the best way to bind them, is there a more standard way?

Here is a fiddle where I omit the above code, but they are now not binded to eachother. We can see that the slider moves much more naturally, however the console reports the same discrepancy between oldVal and newVal.

http://jsfiddle.net/PaulOD/PpCC4/5/

Any help most appreciated. It would also be great if I could find a way to target the slider's true value controls, it feels a bit hacky to just change the css. In jQuery I used to target 'ui.value' and that sorted these issues out great, but I'm trying to do this without jQuery this time.

I'm using the powerange slider. http://abpetkov.github.io/powerange/ EDIT: but I think the choice of slider is not significant as I've reproduced the bug with the html range slider here: http://plnkr.co/edit/ke5n3x?p=preview

Thanks, Paul

도움이 되었습니까?

해결책

it may look like the difference increases but it actually just depends on how fast you "slide". I logged newVal - oldVal and depending on how fast I move the slider the bigger the numbers get. But there are the same on the whole scale. Most of the time I got 21 and 64.

Maybe it seems to you like this because the value is updated multiple times when you slider for a "longer" time (meaning more than a view ms).

Another think on how you made the directives:

Instead of using the parent scope's value preview.donation you should use two-way bindings. Here is an article explaining it: http://umur.io/angularjs-directives-using-isolated-scope-with-attributes/

Cheers

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top