Advertisement
petar_bonov

number scroll

Dec 4th, 2020
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.95 KB | None | 0 0
  1. <script>
  2.     document.addEventListener("DOMContentLoaded", function () {
  3.         const SELECTORS = ["[name=sHours]"];
  4.         let fields = [];
  5.         SELECTORS.forEach(function (s) {
  6.             fields = fields.concat(Array.from(document.querySelectorAll(s)));
  7.         });
  8.         fields.forEach(function (field) {
  9.             field.onwheel = function (event) {
  10.                 let value = parseInt(this.value, 10);
  11.                 const delta = parseInt(this.getAttribute("value"), 10) / 2;
  12.                 if (event.deltaY > 0) value -= delta;
  13.                 else if (event.deltaY < 0) value += delta;
  14.                if (this.hasAttribute("min")) value = Math.max(value, parseInt(this.getAttribute("min"), 10));
  15.                if (this.hasAttribute("max")) value = Math.min(value, parseInt(this.getAttribute("max"), 10));
  16.                this.value = value;
  17.                event.preventDefault();
  18.            };
  19.        });
  20.    });
  21. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement