Advertisement
Guest User

Untitled

a guest
Aug 24th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var savedValue = 25;
  2. var isMouseDown = false;
  3. var isDragging = false;
  4.  
  5. function onMouseDown() {
  6.     isMouseDown = true;
  7. }
  8. function onMouseUp() {
  9.     isMouseDown = false;
  10.     isDragging = false;
  11. }
  12. function onMouseMove() {
  13.     if (isMouseDown) {
  14.         isDragging = true;
  15.     }
  16. }
  17.  
  18. function onInput(input) {
  19.     var step = new Number(input.step);
  20.     var newVal = new Number(input.value);
  21.     var oldVal = savedValue;
  22.     if (
  23.         // Disable the oninput filter with the user is dragging
  24.         // the slider's knob.
  25.         !(isMouseDown && isDragging) &&
  26.             oldVal
  27.     ) {
  28.         input.value = (newVal > oldVal) ?
  29.             oldVal + step : oldVal - step;
  30.     }
  31.  
  32.     savedValue = new Number(input.value);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement