DEV Community

Discussion on: scrollIntoView is the best thing since sliced bread

 
steveblue profile image
Stephen Belovarich

The carousel being full screen makes no difference. If there is overflow of the container, vertical scrollbar will appear. There can still be issues with vertical scrollbars showing up in Ubuntu in particular without any apparent overflow.

I haven't seen this same issue with "the carousel also scrolls to the top of the view port." I've been testing in Chrome Canary with good results.

Thread Thread
 
tiguchi profile image
Thomas Werner • Edited

Ok, I just figured out what my issue is. I'm an idiot who doesn't read the documentation.

I ignored the options arguments inline and block so far. When I implemented my carousel on Mac OS X a couple months ago I only specified 'behavior': 'smooth' and skipped the other two properties. It gave me perfect results back then, and that seems to have changed recently (change of default values?).

Adding the two missing properties fixes the problem though. I get consistent results and scroll behavior in Firefox and Chrome and on both Linux and Mac:

child.scrollIntoView({behavior: 'smooth', inline: 'center', block: 'center'});
Enter fullscreen mode Exit fullscreen mode

Ugh... Sorry for having been such a Debbie Downer here. On the other hand that little conversation with you made me actually look a bit harder and fix the problem in the end. I was about to roll my own scrollIntoView implementation because it looked totally broken to me.

So well... yay, scrollIntoView is actually awesome 😄

For anyone else coming by: please ignore this thread

nothing to see

Thread Thread
 
tunaxor profile image
Angel Daniel Munoz Gonzalez

extra points for that gif

Thread Thread
 
jplindstrom profile image
Johan Lindstrom

Actually, this sub-thread detour specifically just helped me learn about this for a Vue app, so thanks for that everyone :)

Thread Thread
 
kwisatzhazerach profile image
roo kangaroo

I used {block: "nearest"} instead of {block: "center"}. It prevents the vertical scroll.
I also developed a horizontal scroll-carousel. And it works really fine!