Make a Scroll to top button disappear after scrolled to top

Hey Alvaro,

That is correct, you cannot pin individual elements to the page in Studio as of now, like you can in the standard Wix editor. More on that below…

What does a form have to do with a Back To Top button? This is a totally incorrect reference.

As surprising as it may sound, creating a simple Back To Top button on Studio is rather painstaking and complex. This is because Studio for some reason does not allow us to set individual elements such as buttons as Global elements so that they can be added to all pages. This is only available for sections.

So by this logic, you would have to place that button inside a section, set it’s background to transparent, save it as a Global Section, and then go on adding that section individually to each page, make sure it is at the very bottom as the section needs to border the page on all breakpoints in order to pin it, and then finally pin that section to the page. You’d have to do this for each page in your site. However this comes with its own set of flaws.

Since this is a whole section that’s overlapping your page, all other page elements will move behind this section when the user scrolls. So even if the section is transparent and the user can see the content directly in line with the back to top button, they would not be able to click or interact with it in any way. Hope you understood what I’m trying to say here. This attempt to make the UX better would instead end up making it glitchier. Which is why I’d advise against having such a button on Studio, atleast until the ability to set individual elements as Global or something like that is released. However if you badly need it for some reason, then here’s one workaround that worked - you can try doing the same.

This workaround is only for Wix Studio and requires a Pinned Header on the site.

  1. The very first and important step - set your site header to pinned, if not already.
  2. Then bring your header to the front, if not already. (Right-click > Arrange > Bring to Front) This ensure that your Back To Top button does not get hidden behind other sections and elements on the page.
  3. Now add a button to your header. This will be your Back To Top button. Design it as you please.
  4. Then link the button to navigate to the Top of the page when clicked.
  5. Now here’s where the trick lies. From the inspector panel, dock the button to the right, and give it, lets say - a 50px right margin. And then dock it to the top. Give it a top margin of anywhere between 70vh to 85vh. This depends on the size of your button so you will have to play around with it to get the position right. Make sure it is looking good on all breakpoints.

And now its time to add some code. Luckily, the code remains pretty much the same.

  1. Simply click on the button again > three dots > Add Code > Enable Coding > Start Coding. This will pull up the code panel on the bottom and you should see the ID of this button under Properties & Events.
  2. Change the ID of this button to #backToTop
  3. Then click on Open masterpage.js and then set the button’s Default Values to Hidden.
  4. This will open up the code file where you should also see the code for your lighbox as mentioned.
  5. Simply copy and paste this code at the very top of your code.
  1. And then add this line just below the onReady function, like this:

If followed correctly this shouldn’t affect or interfere with any pre-existing code that you might have written. Make sure there are no red lines or errors in the code before testing it out (you might have the wix-window-frontend module imported already for your lightbox code, in that case, you can exclude that line).

And there you go… that’s how you add a Back To Top / Scroll To Top button in Wix Studio (: