I have seen other posts on this topic; however, none of the answers have been detailed enough for me to figure out how to do this. I know how to code in Velo but have no experience with custom elements and don’t really understand how to use them.
I found code online to disable scrolling on Stackoverflow ( [https://stackoverflow. com/questions/4770025/how-to-disable-scrolling-temporarily](https://stackoverflow. com/questions/4770025/how-to-disable-scrolling-temporarily) ) but I am unsure how to implement this on a custom element.
//Page:
function switchScroll(){
$w('#customElemenet').setAttribute('scroll-switch', Date.now().toString() )
}
$w.onReady(() => {
//and when ever you wish to stop scrolling or resume scrolling, run:
switchScroll();
})
Thanks for your response! It doesn’t seem to be working on preview nor on my published site (premium plan)… but I think I did it right? Please see the screenshots attached. Thanks again for the help!
@alexpharaon02 I wouldn’t even try checking it on Preview mode, as custom elements get wrapped by an iframe (on Preview mode only) and therefore behave differently.
However, I thought you want to stop scrolling on user event (such as button click, or scrolling down etc…).
I wouldn’t set the attribute just inside the $.onReady as the custom element may not be ready yet.
If you wish to stop scrolling at the first moment it’s possible - remove the code from the page , and set the attribute via the editor (see the red circle below).
Set the Attribute to scroll-switch and the value to any string you want.
@alexpharaon02 You’re welcome.
but you know that if you want to stop scrolling from page load and never resume it, you don’t need a custom element at all.
You can go to the Site Dashboard > Settings > Custom Code > Add Custom Code
Put this line in there:
<style>body{overflow:hidden;}</style>
Set it to the head and apply to the specific page you need.
Hi @J. D. unfortunately the code is not working to disable scrolling on the mobile site. It does work however on the desktop version. Any ideas? Thanks a lot!
Are you talking about scrolling vertically or horizontally or both?
Which mobile & browser?
Do you need the scrolling sate to be dynamic (i.e. to allow/disallow scrolling when ever you want) or static (i.e never let the user scroll)?
Scrolling vertically. I tested it on an iPhone 8 Plus on Safari. I am not sure if Android (or other) phones suffer from the same problem. I need it to be static (never let the user scroll) but I need to be able to scroll to different parts of the page via code in Velo (eg. after they click a button).