mdbootstrap / perfect-scrollbar

Minimalistic but perfect custom scrollbar plugin. Get more free components with Material Design for Bootstrap UI Kit (link below)
https://perfectscrollbar.com/
MIT License
346 stars 66 forks source link

Touchmove event sticks on thumb #20

Open marcin-koziol opened 3 years ago

marcin-koziol commented 3 years ago

When using PS on "desktop touchscreen" device, the touchmove event should be (probably) unbind in drag-thumb.js on touchend. Currently, if you start using thumb on touchscreen, the scroll beehaviour will work like dragging the thumb despite "dragging" the content div, not the thumb.

Here's a sample that works for me, but some tests are needed to check how many other things it will break ;)

  function unbindTouch() {
    i.event.unbind(i.ownerDocument, 'touchmove', mouseMoveHandler);
  }

  function bindMoves(e, touchMode) {
    startingScrollTop = element[scrollTop];
    if (touchMode && e.touches) {
      e[pageY] = e.touches[0].pageY;
    }
    startingMousePageY = e[pageY];
    scrollBy =
      (i[contentHeight] - i[containerHeight]) /
      (i[railYHeight] - i[scrollbarYHeight]);

    if (!touchMode) {
      i.event.bind(i.ownerDocument, 'mousemove', mouseMoveHandler);
      i.event.once(i.ownerDocument, 'mouseup', mouseUpHandler);
      e.preventDefault();
    } else {
      i.event.bind(i.ownerDocument, 'touchmove', mouseMoveHandler);
      i.event.once(i.ownerDocument, 'touchend', unbindTouch);
    }

    i[scrollbarYRail].classList.add(cls.state.clicking);

    e.stopPropagation();
  }
ARM128bit commented 2 years ago

Why didn't you add a pull request for this issue? I think it's a fine solution!

Could you do it please?

bonjourjoel commented 2 years ago

Yea it works. This fix is good. It's fixes the bug, but if I click outside the thumb, on the rail, then i can't drag. Still good fix.