question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Damping effect gone after calling ev.stopPropagation()

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
sadeghbaraticommented, Nov 11, 2022

you need to be cautious about using stopPropagation

just found a solution from https://github.com/idiotWu/smooth-scrollbar/issues/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

1reaction
mizokcommented, Nov 11, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Event.stopPropagation() - Web APIs | MDN
The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.
Read more >
Pros and Cons of using e.stopPropagation() to prevent event ...
There is no noticeable performance degradation because you allow an event to bubble up because these are user level events and they just...
Read more >
The Dangers of Stopping Event Propagation - CSS-Tricks
We know there's bad advice on the Internet promoting the unnecessary use of stopPropagation , but that isn't the only reason people do...
Read more >
How to correctly use preventDefault(), stopPropagation(), or ...
Prevents the event from bubbling up the DOM, but does not stop the browsers default behaviour. For an in-depth explanation of event bubbling,...
Read more >
Event Bubbling and Event Catching in JavaScript and React
⚠️ If we use event.stopPropagation() , it would stop one event handler from triggering – but then you would never be able to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found