Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSS-scroll-snap] Unable to scroll the area where CSS-scroll-snap is set #66

Open
dnknn opened this issue Oct 2, 2023 · 2 comments
Open
Labels
question Further information is requested

Comments

@dnknn
Copy link

dnknn commented Oct 2, 2023

Add the following CSS, then Unable to scroll the image area

:root	{
	scroll-snap-type:y mandatory;
	/* scroll-snap-type:y */
}
.mb-3.Box	{scroll-snap-align:start}
document.documentElement.style.cssText += `scroll-snap-type:y`;
document.querySelector`.mb-3.Box`.style.cssText += `scroll-snap-align:start`;

Of course, this is the behavior of the API itself, I just raised a question to discuss, maybe there is a JS-API that can temporarily release the scroll snap?

API-Doc:  CSS scroll snap | MDN⤤   scroll-snap-type | MDN⤤  

  • I still feel like there is no good solution...^_^

    After all, CSS-scroll-snap is generally only used in specific places.

addEventListener(`mousedown`,e=>	{
	if(e.button===`1` &&!e.ctrlKey&&!e.shiftKey&&!e.altKey)	{
const cssSnap = getComputedStyle(document.documentElement).scrollSnapType
	//Continuously calculating style collections seems to affect performance ^_^
if(cssSnap&&cssSnap!=`none`)	.....

	}

});

addEventListener(`mouseup`,e=>	{
	if(e.button===`1` &&!e.ctrlKey&&!e.shiftKey&&!e.altKey)	...Restore user settings css-scroll-Snap
});
@dnknn dnknn added the question Further information is requested label Oct 2, 2023
@Juraj-Masiar
Copy link
Member

This reminds me "scroll-behavior: smooth" which some pages uses and it is also interfering with the scrolling.
In that case I'm simply overriding it completely once user starts scrolling and not reverting it (I think I was just lazy to implement the revert since I would have to await the "momentum" to finish scrolling, so not just on mouse up. Plus people are unlikely to notice the scroll behavior change.).

So in this case I should probably also disable it but also re-enable it once the scrolling is done (including momentum) which should then align scroll position to the correct snap position.

I'll see what I can do once I start working on a new release :)
Thank you for reporting this!

@dnknn
Copy link
Author

dnknn commented Oct 2, 2023

Thanks for the reply!
For this case, I don't think the impact is big, so it doesn't matter if you don't do anything, Just knowing the problem is enough ^_^
If you want to do anything, you should add an additional configuration option, otherwise I'm afraid it will create new bugs or performance issues. @Juraj-Masiar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants