Hello Wixers, The name of this tutorial might be wrong as I’m not a coder so I kindly ask the moderators to correct the title name if its wrong for search purposes…
About
Ever seen a website where scrolling is controlled? Controlled means that when you scroll once it takes you to the next section without scrolling too much (one scroll touch)? Well if you wanna know how on wix, then you are in the right place… Please note that this feature was requested from wix support but they said its not available in wix but with some hard working research and alot of trying and failing, I give you the feature using WIXCODE and ANCHORS .
The Result
Live Example Here https://samidesigns.wixsite.com/samidesign
This is a One-Scroll-Touch so you only scroll once to go to the next section and even if you try scrolling rapidly it will not respond to it.
Working With Anchors
For this to work you will need to work very carefully with anchors, One wrong move and it will not work and it will look messy. So follow the tutorial step by step:
Setting up Scroll Down
- Drag and drop an anchor from the left side menu in the wix editor and name it Anchortop, Right Click on it > Properties > ID and rename it to Anchortop as well
- Place Anchor Anchortop at the very top of your websites’ page
3. Drag and drop a second anchor from the left side menu in your editor. In my case, my next section is my featured design work so i called it tofeaturedwork or you can keep its name “anchor2” as long as you dont get confused later on but feel free to name it as you wish and bare in mind these names will be used later for coding. Place the anchor close to the Anchortop
but not too close so it wont trigger automatically on loading and without scrolling.
- Right Click on it > Properties > set ID to tofeaturedwork
In the Events section:
onViewportLeave >
Click the small + button on the right to add the event so you will see this:
tofeaturedwork_viewportLeave
Before pressing enter to save add " on " to the event so it becomes this:
tofeaturedwork_onviewportLeave
Leave the onViewportEnter empty.
Your setting should look exactly like this:
5. Drag and drop a new anchor and place it on the next section in the page you want the visitors to go to when scrolling down.
Name it as you wish then right click > Properties > ID “Section Name” I named it featuredwork
Event Section will be clear and nothing to add there.
Setting up Scroll Up
- Add a new anchor and call it “backtop”
- Place it near to and on top of anchor2 or on top of the anchor of your current section so when the visitor scrolls up, it takes him to the previous section. Dont place too near or it will automatically scroll up when loaded and not too far so your visitor wont see the empty space in the website, Has to be reasonable distance.
Circled Red: Is the Scroll Up Trigger
Circled Blue: Is the current section
- Right Click > Properties > ID backtop as well
- Events Section Setup:
onViewportEnter > Click the small + on the right and you will see:
backtop_viewportEnter now add “on” after the underscore so it will be :
backtop_onviewportEnter
Your settings should look like this:
Working With Codes
After you have saved and done the Working With Anchors , Go down to the code console and clear any codes from the “page” section.
STOP,
Ok now before we move on any further, let us revise and list the anchors and understand the logic of this:
- tofeaturedwork : This is the scroll down trigger which will take the visitor down to the next section on the page called “Featured Work” when scrolling.
- featuredwork : Is the destination of the Scroll down.
- backtop : Is the scroll up trigger which will take the visitor up to the previous section when scrolling
- Anchortop : Is the destination of the scroll up trigger backtop
Codes
This code should go into “Site” Tab in your site codes section.
export function tofeaturedwork_onviewportLeave() {
$w("#featuredwork").scrollTo();
}
export function backtop_onviewportEnter() {
$w("#Anchortop").scrollTo();
}
All questions are welcome
UPDATE 10 April 2018 : Unfortunately after running some more tests, This Method will only work on two sections and will be a complete mess if you try to do it to more than two sections on your page, I have tried over and over and over again for 4 straight hours to over come the issue but no avail. So I recommend using this if you want to do it for two sections, other than that I apologize WIX havent added this feature yet and its still in the suggested features section in the support
SamiDesigns