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.

Manual scroll should cancel/override our scroll?

See original GitHub issue

With the current implementation, if the user does a manual scroll while the element is being scrolled by scrollIntoView, there is a jank and zig-zag scrolling, which I think is because scrollIntoView is trying to finish its scroll. Can we have an option to discard the automated scroll once user does a manual scroll?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
KoryNunncommented, Oct 10, 2019

Do you want it to finish immediately or just completely take over the users inputs and complete the animation?

For instant completion, you can do:

scrollIntoView(target, function(type){
	if(type === 'canceled'){
		scrollIntoView(target, { time: 0 });
	}
});

which will instantly set the scroll to the correct position when the user attempts to override it.

Alternatively, For scroll-jacking, I have a few suggestions:

Option 1. Don’t scroll jack. Option 2. If you must scroll-jack, bind your own handlers to prevent scroll events from hitting scroll-into-view and remove them when scrolling is complete, something like:

function scrolljack(event){
	event.stopPropagation();
	event.preventDefault();
}
window.addEventListener('touchmove' scrolljack, true); // <- `true` makes this handler fire on the capture phase, which happens before the bubble phase, so it will be called well before scroll-into-view sees it.
window.addEventListener('mousewheel' scrolljack, true);

scrollIntoView(target, function(
	window.removeEventListener('touchmove' scrolljack, true);
	window.removeEventListener('mousewheel' scrolljack, true);
});

The above is untested, consider it psudocode. It’s also horrific and I highly recommend you don’t do it.

1reaction
KoryNunncommented, Mar 13, 2019

Hey, thanks for the find,

This already exists for touchstart, just needs to be added for mousewheel.

Send a pr or I’ll get to it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to cancel a javascript function if the user scrolls the page
How would I go about cancelling this action if the user scrolls manually before the 5s is elapsed. Reason being if the user...
Read more >
Element.scroll() - Web APIs - MDN Web Docs
Chrome Edge scroll Full support. Chrome61. Toggle history Full support. Edge79. T... options.behavior parameter Full support. Chrome61. Toggle history Full support. Edge79. T... options.left parameter Full...
Read more >
Installing & Configuring our Cancel Override Add-on
The first step to set Cancel URL is to go to MemberPress → Settings → Account, scroll down to the "Cancel Override Settings"...
Read more >
Scroll - LVGL documentation
In LVGL scrolling works very intuitively: if an object is outside its parent content area (the size without padding), the parent becomes scrollable...
Read more >
Scrollbar | Unity UI | 1.0.0 - Unity - Manual
A significant difference between the Scrollbar and the similar Slider control is that the Scrollbar's handle can change in size to represent the ......
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