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
clevermissfox11mo ago
Do you have media queries in your css somewhere that changes anything?
SpongeBob
SpongeBobOP11mo 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
clevermissfox11mo 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
SpongeBobOP11mo ago
I just tried on google chrome as of now. wait a sec, let me try on firefox once
clevermissfox
clevermissfox11mo ago
Is the scrolling not working or just the behaviour "smooth"?
SpongeBob
SpongeBobOP11mo ago
scrolling itself not working not working on firefox as well.
clevermissfox
clevermissfox11mo 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
SpongeBobOP11mo 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
clevermissfox11mo 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
SpongeBobOP11mo ago
top of the form, I tried that doesnt seem to work. tried, no luck.
clevermissfox
clevermissfox11mo 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
SpongeBobOP11mo 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
clevermissfox11mo 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
SpongeBobOP11mo 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
clevermissfox11mo 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
SpongeBobOP11mo ago
waitt I dont know how but it worked
clevermissfox
clevermissfox11mo ago
What happened
SpongeBob
SpongeBobOP11mo ago
😆 I am also checking, how it worked now 🤣
clevermissfox
clevermissfox11mo 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
SpongeBobOP11mo ago
yeah I think I added some styling, I am just checking, what exactly it did
SpongeBob
SpongeBobOP11mo 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
clevermissfox11mo ago
❣️
SpongeBob
SpongeBobOP11mo ago
hey @hart❤🔥 , its fixed
clevermissfox
clevermissfox11mo ago
What did you learn About what was happening
SpongeBob
SpongeBobOP11mo 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
clevermissfox11mo 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
SpongeBobOP11mo ago
oh I never heard of svh whats that
clevermissfox
clevermissfox11mo 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
SpongeBobOP11mo ago
yeah 😅 thank you @hart❤🔥 once again
glutonium
glutonium11mo 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
SpongeBobOP11mo ago
😆
Want results from more Discord servers?
Add your server