Automatic scroll is not working for certain pixels 320px to 1023px.

Hi everyone, I will not be able to share the code and screenshots for my issue as we have client restrictions. Help me, if you ever faced this issue. Problem: We have a implementation on our web app that on click of a button the screen automatically scrolls to the top of the page, but this scrolling behavior is not happening for the screen between 320px to 1023px. For other resolutions its working fine. The code we are using to automatic scroll is
document.querySelector(`#forms-section`)?.scroll({
top: 0,
behavior: 'smooth'
});
document.querySelector(`#forms-section`)?.scroll({
top: 0,
behavior: 'smooth'
});
32 Replies
clevermissfox
clevermissfox10mo ago
Do you have media queries in your css somewhere that changes anything?
SpongeBob
SpongeBob10mo ago
Thats what I also thought about, but I dont see any scroll css being getting changed. Do you know if any other css property can affect the scroll functionality? @hart❤🔥
clevermissfox
clevermissfox10mo ago
Not just scroll properties but anything that happens within queries for those breakpoints is what I'd look at. Things like this is always "it depends" bc everything depends on everything else. Have you tested on different browsers, different devices, different oS's?
SpongeBob
SpongeBob10mo ago
I just tried on google chrome as of now. wait a sec, let me try on firefox once
clevermissfox
clevermissfox10mo ago
Is the scrolling not working or just the behaviour "smooth"?
SpongeBob
SpongeBob10mo ago
scrolling itself not working not working on firefox as well.
clevermissfox
clevermissfox10mo ago
So you want it to scroll to the top of the document or the tip of the form? I would try troubleshooting to put the same function on different elements. You could always just change it scrollTo(x,y) and then in your css , under a @prefers-reduced-motion add scroll-behaviour smooth there. Dot forget to use dev tools that's what they're there for. Are you getting any errors? What is that question mark in the code you posted ? After the querySelector function ?
SpongeBob
SpongeBob10mo ago
Thats a optional chaining I think, not sure if that is required. I dont see any error in console. Let me give it a try, so in scrollTo I can directly apply like this
document.querySelector("#forms-section").scrollTo(x, y)
document.querySelector("#forms-section").scrollTo(x, y)
?
clevermissfox
clevermissfox10mo ago
On an event But yes, are you wanting to scroll to the top of the document or the top of the form ? If the latter you have to find or approximate the x/y axis you want to scroll to "The optional chaining ( ?. ) operator accesses an object's property or calls a function. If the object accessed or function called using this operator is undefined or null , the expression short circuits and evaluates to undefined instead of throwing an error." Maybe take off the question mark and see if theres an error
SpongeBob
SpongeBob10mo ago
top of the form, I tried that doesnt seem to work. tried, no luck.
clevermissfox
clevermissfox10mo ago
It's within the event ? Dis you check for errors now that you took off the optional chaining operator ? Within your event, like the button click, try scrollTo(0,0) on the body to see if it scrolls to the top. There is enough content on the page to scroll?
SpongeBob
SpongeBob10mo ago
yes enough content on the page. yeah I removed, no error on console. its difficult for you to figure out the issue this way as you dont know the exact thing what is happening. I cant share screenshot too 🥲
clevermissfox
clevermissfox10mo ago
Yes it's very hard to troubleshoot without all the code. You have your scrupt linked properly yes? You jave properly selected the button? I would pull out the dev tools and start putting stops around that error and console.logs , old-school
SpongeBob
SpongeBob10mo ago
I think the issue is not with code, if that was the issue, it wouldnt have worked for other resolutions. Definitely its styling issue somewhere. f*** it worked
clevermissfox
clevermissfox10mo ago
Wait is it the top of the page or the top of the form? In your post you say top of the page which I didn't see before? Is the form far enough down on the page for a scrollbar ? Is there any position properties declared in that media query? I'd go through and put stops like I said, start commenting out classes from your media queries in that range
SpongeBob
SpongeBob10mo ago
waitt I dont know how but it worked
clevermissfox
clevermissfox10mo ago
What happened
SpongeBob
SpongeBob10mo ago
😆 I am also checking, how it worked now 🤣
clevermissfox
clevermissfox10mo ago
Well , that's too bad you don't know why so you couldn't know how to fix it but good news is good news ! Yeah try to figure out what it was I'm invested and curious now 🤣
SpongeBob
SpongeBob10mo ago
yeah I think I added some styling, I am just checking, what exactly it did
SpongeBob
SpongeBob10mo ago
styling is breaking somewhere else now. I will take a look @hart❤🔥 but thanks for your help I will revert if I fix this
clevermissfox
clevermissfox10mo ago
❣️
SpongeBob
SpongeBob10mo ago
hey @hart❤🔥 , its fixed
clevermissfox
clevermissfox10mo ago
What did you learn About what was happening
SpongeBob
SpongeBob10mo ago
To be honest, I really dont how they have written css, but somewhere on the forms-section parent element, the height, height: 100vh; was missing it works like butter now till I notice a bug in production 😆
clevermissfox
clevermissfox10mo ago
Hm that shouldn’t have affected the scroll… heights shouldn’t be set and if they are it should be a min-height to prevent overflow . Content and padding should make up the size. But either way glad it’s working now Don’t forget to change to 100svh since it’s gonna be on mobile
SpongeBob
SpongeBob10mo ago
oh I never heard of svh whats that
clevermissfox
clevermissfox10mo ago
Helps keep your vh working on mobile browsers to account for the ui like the address bar. dvh and svh are pretty new but fully supported and better fir user experience (Actually users probably never notice the jump when scrolling down but better for all the devs anxiety and sanity 🤣 )
SpongeBob
SpongeBob10mo ago
yeah 😅 thank you @hart❤🔥 once again
glutonium
glutonium10mo ago
welcome to programming linux I ran my C code, got seg fault. Commented out part of code.. still seg fault.. uncommented it.. works
SpongeBob
SpongeBob10mo ago
😆
Want results from more Discord servers?
Add your server