Advertisement
Siri0n

Untitled

Sep 18th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var MAX_FILTER_PRICE = 1500;
  2.  
  3. var makeDraggable = function (element, moveCallback) {
  4.  
  5.   element.addEventListener('mousedown', function (evt) {
  6.     evt.preventDefault();
  7.  
  8.     var startPointerCoords = {
  9.       x: evt.clientX
  10.     };
  11.  
  12.     var startElementCoords = {
  13.       x: element.offsetLeft
  14.     };
  15.  
  16.     var onMouseMove = function (moveEvt) {
  17.       moveEvt.preventDefault();
  18.       var shift = {
  19.         x: startPointerCoords.x - moveEvt.clientX
  20.       };
  21.       element.style.left = (startElementCoords.x - shift.x) + 'px';
  22.       moveCallback && moveCallback();
  23.     };
  24.  
  25.     var onMouseUp = function (upEvt) {
  26.       upEvt.preventDefault();
  27.       document.removeEventListener('mousemove', onMouseMove);
  28.       document.removeEventListener('mouseup', onMouseUp);
  29.     };
  30.     document.addEventListener('mousemove', onMouseMove);
  31.     document.addEventListener('mouseup', onMouseUp);
  32.   });
  33. };
  34.  
  35. var rangePriceMax = document.querySelector('.range__price--max');
  36.  
  37. function updateMaxPrice(){
  38.   var value = getSliderValue(btnRight);
  39.   var price = value * MAX_FILTER_PRICE;
  40.   price = Math.round(price);
  41.   rangePriceMax.innerText = price;
  42. }
  43.  
  44. makeDraggable(btnRight, updateMaxPrice);
  45.  
  46. makeDraggable(btnLeft);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement