How to Create Active Links on Scroll for One-Page Divi Websites

Last Updated on September 16, 2022 by 19 Comments

How to Create Active Links on Scroll for One-Page Divi Websites
Blog / Divi Resources / How to Create Active Links on Scroll for One-Page Divi Websites
Play Button

In todayโ€™s tutorial weโ€™re going to show you how to style your vertical navigation links so that as a visitor scrolls down the page, the menu link corresponding to the section theyโ€™re in will highlight. Itโ€™s a nice little effect that adds a bit of interactivity between your web design and the userโ€™s behavior. This method works particularly well if youโ€™re creating a one-page website.

For those having a hard time picturing this effect in their mind, weโ€™ve provided a preview below.

Result

Letโ€™s have a look at the final result youโ€™ll be able to achieve after following this post:

active links

As you can see, the highlighted active link changes automatically as the user scrolls through the page sections (as well as on click).

Inspiration

We found our inspiration for this post at the Filmschool Berlin website which we mentioned as an example in our post on vertical navigation. A reader in the comments of that post asked that we show them how to create the scrolling active link effect and so here we are!

active links

How to Create Active Links on Scroll for One-Page Divi Websites

Subscribe To Our Youtube Channel

Getting Started: Download The Page Scroll to ID Plugin

To pull this design off weโ€™re going to begin by making use of the free and well-rated Page Scroll to ID plugin which you can find here. Click on the โ€˜Downloadโ€™ button and save the plugin ZIP file somewhere where you can find it right away.

active links

Upload & Activate The Page Scroll to ID Plugin

The next thing youโ€™ll need to do is go to your WordPress Dashboard > Plugins > Add New > Select the ZIP file youโ€™ve just downloaded and upload it.

active links

After that, donโ€™t forget to activate the plugin as well.

Enable Vertical Navigation

Before we get into the settings of the Page Scroll to ID plugin, weโ€™ll enable the vertical navigation (and the fixed navigation in the next step) first. If youโ€™re on your WordPress Dashboard, go to Appearance > Customize > Header & Navigation > Header Format > And enable vertical navigation.

active links

Enable Fixed Navigation

Moving on, letโ€™s enable the fixed navigation of your website. This is necessary since the whole point of using the active links on scroll is for the visitors to see which section they are in, when theyโ€™re in it. If youโ€™re on your WordPress Dashboard, go to Divi > Theme Options > And enable the Fixed Navigation Bar in the General tab.

active links

Page Scroll to ID Plugin Settings

For this part, weโ€™re going to go back to the plugin that was recently uploaded. Once youโ€™ve activated the plugin, youโ€™ll need to use the right settings. To go to the settings, click on โ€˜settingsโ€™ right below the plugin name.

active links

Once youโ€™ve done that, youโ€™ll notice the different options that help you determine how the active links will behave on your website. For the example weโ€™ve made, weโ€™re using the following settings:

  • Enable on WordPress Menu Links: Yes
  • Scroll duration: 200 milliseconds
  • Auto-adjust scrolling duration: Yes
  • Scroll animation easing: Linear
  • Always scroll smoothly when reaching the end of the page/document: Yes
  • Stop page scrolling on mouse-wheel or touch-swipe: Yes
  • Page layout: auto
  • Allow only one highlighted element at a time: Yes
  • Keep the current element highlighted until the next one comes into view: Yes
  • Highlight by next target: Yes
  • Append the clicked linkโ€™s hash value to browserโ€™s URL/address bar: Yes
  • Scroll from/to different pages: Yes
  • 0 milliseconds delay for scrolling to target on page load
  • Prevent other scripts from handling pluginโ€™s links (if possible): Yes
  • Normalize anchor-point targets: Yes

active links

active links

active links

Add CSS ID & Class to Sections

The next thing youโ€™ll need to do is assign the different CSS IDs and the Page Scroll on ID CSS Class to the different sections on your one-pager. To do that, open the settings of each one of your sections and go to the Advanced tab. Within the Advanced tab, decide on the different CSS IDs you want to use for your sections. Know that, in order for it to work, youโ€™ll have to assign a different CSS ID to each one of the sections on your one-pager.

activelinks

In this example, weโ€™re using โ€˜homeโ€™ as our first CSS ID. The CSS Class, however, is the same for each one of the sections and helps you link the section to the Page Scroll to ID plugin. The CSS class name is โ€˜ps2idโ€™.

Add ID to Menu Items

Next up, itโ€™s time to create the menu items and make sure theyโ€™re in line with the sections and with the Page Scroll to ID plugin. If youโ€™re on your WordPress Dashboard, go to Appearance > Menus. If you already have a primary menu, you can work on that one. If not, you can type down the title and create a new menu. Donโ€™t forget to make it a primary menu.

Use Custom Links

Next, youโ€™ll be needing custom links to achieve the results you want. Start by adding a first custom link. Add your website followed by the first section ID to the link field as shown in the screen shot below.

Enable CSS Classes

The next thing youโ€™ll need to do, if you havenโ€™t done it in the past already, is activate the CSS classes for your menu items. To do that, click on the โ€˜Screen Optionsโ€™ option in the right corner. Once the possibilities appear, enable the CSS classes.

active links

Use Page Scroll to ID CSS Class

Once youโ€™ve enabled the CSS classes for your menu items, you can go ahead and manually link the Page Scroll to ID class to each one of the menu items. The CSS class is the same as weโ€™ve used to assign IDs to our sections, namely โ€˜ps2idโ€™.

active links

Make Appearance Modifications

You can make all kinds of modifications to your primary menu, even when youโ€™re using this method. To show you how you can make the changes, weโ€™re going to recreate our example vertical navigation.

Note:ย As mentioned in the introduction of this post,ย you wonโ€™t be able to see the changes youโ€™ve made while youโ€™re previewing the page. You have to publish the page first and view it in its live modus to notice the results.

Theme Customizer

Start by going to the Theme Customizer > Header & Navigation > Primary Menu and make the following changes to how your primary menu will look like:

  • Hide Logo Image: Yes
  • Logo Max Height: 83
  • Menu Top Margin: 0
  • Text Size: 14
  • Letter Spacing: -1
  • Font: Lato Light
  • Font Style: Capitals
  • Text Color: #FFFFFF
  • Active Link Color: #FFFFFF
  • Background Color: rgba(255,255,255,0)
  • Dropdown Menu Background Color: rgba(255,255,255,0)

active links

active links

Custom CSS Theme Options

To change the active link style, weโ€™ll have to add some Custom CSS code. If youโ€™re on your WordPress dashboard, go to Divi > Theme Options > Scroll down the General tab and paste the following lines of CSS code in the Custom CSS box:

#top-menu .current-menu-item a.mPS2id-highlight{
background: black;
border-top: 1px solid #FFFFFF;
border-bottom: 1px solid #FFFFFF;
padding-top: 15px;
}

Besides that, weโ€™ve also used an overlapping transparent menu, which weโ€™ve handled more in detail in this post. To apply those CSS changes to your website as well, copy and paste the following lines of CSS code in the Custom CSS box as well:

@media (min-width: 981px) {
.et_vertical_nav #et-main-area, .et_vertical_nav #top-header {
margin-left: 0px !important;
}
.container {
margin-left: 3% !important;
}
.et_vertical_nav #page-container #main-header {
box-shadow: none !important;
}
}

active links

Results

When having followed all the steps in this post, you should be able to achieve this final result:

active links

You can, of course, modify the style to your own preferences (or use it for top navigation as well).

Final Thoughts

In this tutorial, weโ€™ve shown you how to create an interactive vertical navigation menu for one-pagers. Weโ€™ve shown you how you can use the Page Scroll to ID plugin in combination with the Divi theme to easily achieve the result you want to get. In a future post, weโ€™ll come back to this and show you how to creatively style the active links youโ€™re using through this method. If you have any questions or suggestions, make sure you leave a comment in the comment section below!

Be sure toย subscribe to our email newsletterย andย YouTube channelย so that you never miss a big announcement, useful tip, or Divi freebie!

Featured Image by Yurlick / shutterstock.com

Divi Marketplace

Are You A Divi User? Find Out How To Get More From Divi! ๐Ÿ‘‡

Browse hundreds of modules and thousands of layouts.

Visit Marketplace
Divi Marketplace
Divi Cloud

Find Out How To Improve Your Divi Workflow ๐Ÿ‘‡

Learn about the new way to manage your Divi assets.

Get Divi Cloud
Divi Cloud
Divi Hosting

Want To Speed Up Your Divi Website? Find Out How ๐Ÿ‘‡

Get fast WordPress hosting optimized for Divi.

Speed Up Divi
Divi Hosting
Premade Layouts

Check Out These Related Posts

Get a Free Coffee House Layout Pack For Divi

Get a Free Coffee House Layout Pack For Divi

Posted on April 22, 2024 in Divi Resources

Hey Divi Nation! Thanks for joining us for the next installment of our weekly Divi Design Initiative; where each week, we give away a brand new Layout Pack for Divi. This time around, the design team has created a beautiful Coffee House Layout Pack thatโ€™ll help you get your next Coffee House...

View Full Post
Get a Free Butcher Shop Layout Pack for Divi

Get a Free Butcher Shop Layout Pack for Divi

Posted on April 15, 2024 in Divi Resources

Hey Divi Nation! Thanks for joining us for the next installment of our weekly Divi Design Initiative; where each week, we give away a brand new Layout Pack for Divi. This time around, the design team has created a beautiful Butcher Shop Layout Pack thatโ€™ll help you get your next Butcher Shop...

View Full Post

19 Comments

  1. Thanks for that cool solution
    What would be the selector if i wanted to change the link color of the text only not the background of the menu?

    • Thanks for the great tutorial. can we achieve this functionality for specific section or row?

  2. Hi, for me it was very useful, tutorial gave me exactly, what I was looking for to customize my own website! Great help! Thanks a lot!

  3. All links remain highlighted. I have only a primary and a secondary, but the primary is the one controlling the scrolling to anchors. I have the ps2id on every one of the main section “divs” or boxes in Divi Visual Builder Tool. I followed tutorial very carefully but nav is not responding.

  4. Hi, is there some code that I can put in the custom CSS section that does the following: I have a primary menu and a fixed navigation menu, what ends up happening now is that my fixed navigation menu turns all white(or any color that i set it to) and doesn’t highlight the current section. please help.

  5. Thanks for the information! We’ve been trying to get this to work, and the scrolling is perfect, however cannot get it to highlight the correct section when manually scrolling the page. We’ve tried everything!

    Has anyone else experienced this?

    • Yes, highlighting does not work. Only, when I scroll up again, there is a menu-entrance highlighting. But only one and the wrong one ๐Ÿ™

      • Hi Katrin and Liam,

        I just tried it out and the highlighting works perfectly well here, even when manually scrolling. (The only difference: I am working with a horizontal menu, but I am sure it’s absolutely the same with the vertical version.)

        Are you sure you followed every single step of the tutorial and didn’t forget some bits? That might be a reason, or some other plugin or JavaScript that could lead to an incompatibility.

        @Donjete and @Mak
        Thanks a lot for another excellent tutorial, I love these in-depth tutorials where I can learn how to work with Divi. Really helpful and inspiring!

        • I’ve just tried the vertical version, and the highlighting (even when manually scrolling) works perfectly well here, too. I wonder what is getting in your way there.

          • I had the same problem with highlighting. I found that, in order to make the highlight apply to the correct menu item, each sections need to be long enough to fill the screen. Once I did this, the highlighting worked perfectly.

  6. This is the topic, I asked your support team for half a year now. I never got an answer. Why could’nt you post it earlier, before I killed myself?

    I will try it out now. But does it also work on horizontal menu?

    • Hi Katrin,

      >> Why couldโ€™nt you post it earlier, before I killed myself?

      That made me chuckle, nice to have you back. ๐Ÿ™‚

      >> But does it also work on horizontal menu?

      See above:
      “You can, of course, modify the style to your own preferences (or use it for top navigation as well).”

  7. This would be possible even without using the Page Scroll to ID plugin, wouldn’t it?

  8. Love the idea, Thanks for tips

  9. This plugin will be very helpful

  10. This is great! Thanks.

  11. Been looking for this, sorta! Is it possible to do this with a centered fixed menu as well? The kind of menu that changes when scrolling down. I’m getting it to work on page load, but I’m guessing the menu links change class on scroll and I need to apply the above css to that one as well ๐Ÿ˜›

  12. Can this be used to create a sticky secondondary menu?

  13. I wish I saw this earlier this year. I just used anchor links in the menu items pointing to CSS IDs I created in each section.

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Join To Download Today