idiotWu / smooth-scrollbar

Customizable, Extendable, and High-Performance JavaScript-Based Scrollbar Solution.

Home Page:https://idiotwu.github.io/smooth-scrollbar/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Damping effect gone after calling ev.stopPropagation()

mizok opened this issue · comments

commented

Checks

  • Not a duplicate.

Version

8.8.1

Description

Just same as title.

I was trying to stop touch event bubbling, then I found If I use ev.stopPropagation() , it will cause the scrollbar damping effect disappear.

Steps to Reproduce

  1. create a normal smooth-scrollbar-inited container
  2. bind on touchend event on any element in the normal smooth-scrollbar-inited container.
  3. in the event handler, call ev.stopPropagation()

Online Demo

No response

Please just fork it and explain with more details cause I can't reproduce it

commented

@sadeghbarati

Sorry, I found I made a mistake, it's touchend event, not click.

If you need to check it with this stackblitz demo below, you will have to switch to mobile mode (with touch) ( chrome developer tool).

You will notice that the damping effect just disappear after the touchend event trigger by "touchend" that "stopPropagation" button.

https://stackblitz.com/edit/vitejs-vite-hglpla?file=main.js

commented

My solution now is not to use ev.stopPropagation, but detect if the event.target is descendant of elements from which I want to stop the event bubbling.

But I think it's not a very good solution since it's not very intuitive, it will be nice if you guys could fix it 😭 .

you need to be cautious about using stopPropagation

just found a solution from #444

class SmoothTouchScrollPlugin extends ScrollbarPlugin {
  static pluginName = 'smoothTouchScroll';

  transformDelta(delta, fromEvent) {
    if (fromEvent.type === 'touchmove') {
      this.scrollbar.options.damping = 0.1;
    }

    return delta;
  }
}

https://stackblitz.com/edit/vitejs-vite-9e2btw?file=main.js