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.

Scrollbar jumps after Dragging manually with mouse

See original GitHub issue

OverlayScrollbar works as expected until you use the mouse to drag the scrollbar, after which it starts jumping on each mouse move.

Version: 1.4.1 (1.4.4 does not work with AMD) Options:

 {
          scrollbars: {
                autoHide: 'leave',
                autoHideDelay: 300
          }
}

Browser: Chrome, Firefox

I use the Plain Javascript version. Here is a demo of the problem:

scrollbar

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KingSoracommented, May 18, 2018

Phu, I’m glad this fix worked.

Alright let me explain:

In the code, I’m initializing the events for the scrollbars in a method called initScrollbarInteractivity. The dragging of the scrollbar handle-element works like this:

  1. A mousedown event on the handle-element registers a mouse “click” with the left button
  2. Then a mousemove event gets applied to the document-element, so you can actually move the mouse around the whole page to drag the scrollbar handle. Simultaneously a mouseup event gets applied to the document-element. The purpose of this event is to reset this whole secenario (remove the mousemove event from the document-element and so on)

For the mousemove and mouseup events I’ve used passive event listeners. Passive event listeners are relatively new. Unfortunately (and I really don’t know why) these listeners can’t be removed from the document-element in some cases. You also don’t have the possibility to check whether the removal was successful or not. So the bug was caused because the mousemove event was still applied to the document-element although it should be removed.

I’ve tested it on different elements and it seems like the document-element is the only element which reacts in this way. On the body, html or other elements the removal of the listeners is working always without any problems (since I’m using them on other elements too). Since this bug is happening under very special conditions (it’s happening on your page but not on mine and so on), I’m still thinking this is a browser bug, but since I can’t really identify what is causing it, I also can’t report it.

So what was the fix? - The fix was to use normal events instead of passive events on the document-element. Probably youre asking yourself now whether the performance is now worse than it was with passive events. The answer is a simple no, because I used the passive events only because I thought the performance could be better with them.

Passive events also don’t really affect mouse events since they are intended to be used on touch events. But why did I use them on mouse events at all? - Because in my code I’ve grouped mouse and the corresponding touch events to reduce the code size (you can check the variables: _strMouseTouchDownEvent, _strMouseTouchUpEvent and _strMouseTouchMoveEvent). Since passive events gets only applied if the event “allows” and is suited for it, they doesn’t have any negative side effects, so why not.

Some browsers such as Google Chrome are marking all touch events on the document-element as passive events by default, so in the best case the browser will make the events as fast as possible automatically.

I hope I could give you some insight and it is now more clear why this behavior was also very strange for me.

0reactions
KingSoracommented, May 18, 2018

Verison 1.4.5 with the fix is now released!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix Mouse Scroll Wheel Jumping in Windows 10 ...
Go to the Wheel tab. Under Vertical Scrolling, lower the number of lines that the mouse wheel can scroll. Now, move to the...
Read more >
Manually fixed content jumps when scrolling with mouse ...
Manually fixed content jumps when scrolling with mouse wheel in FireFox ... But these elements are jumping when scrolling with mousewheel in ...
Read more >
vertical scrollbar thumb jumps back to original position when ...
1. Go to a page with a vertical scrollbar · 2. Scroll down the page · 3. Drag the scrollbar thumb upwards. As...
Read more >
Why do scrollbars revert to original scroll distance when ...
When dragging the scrollbar using the mouse, the contents of the scrollpane move up and down as the bar moves with the mouse....
Read more >
Annoyances of scrollbar behaviour :: Suggestions / Ideas
Not with this bug. a scrollbar DONT jump when you mouse-hover it. just try it yourself, move your mouse into the scrollbar. nothing...
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