Click Dropdown – Scroll to top of page

Description

#1. Install Code

#1.1. First, we need to describe request a bit

  • We have a dropdown with title name: Services
  • When users are on Services page > Click dropdown title Services > Scroll to top of page
  • When user are on other pages > Click dropdown title Services > Open Services page (/services) and scroll to top of page

#1.2. First you need to know this. It is the order of navigation items from left to right, increasing from 1.

  • In my example, Services dropdown is 3

05.26c15v2 Click Dropdown Scroll to top of page

#1.3. Add this code to Code Injection > Footer

  • If you use Personal/Basic Plan and your plan doesn’t support Injection, you can see step #3.1.
<script>
window.SCROLL_TOP_CONFIG = {
  selector: '.header-nav-item:nth-child(3)',
  href: '/services'
};
</script>
<script src="https://code.beaverhero.com/header/0526c15v2clickdropdowntitlescrolltop.js"></script>

05.26c15v2 Click Dropdown Scroll to top of page

#1.4. Remember to update number 3

selector: '.header-nav-item:nth-child(3)',

05.26c15v2 Click Dropdown Scroll to top of page

#2. Customize

#2.1. If you want to open another page when click dropdown title, you can edit Line 04

href: '/services'

05.26c15v2 Click Dropdown Scroll to top of page

#3. Other

#3.1. If you use Personal/Basic Plan and your plan doesn’t support Injection, you can edit SITE FOOTER

05.26c08v1 Event Default Location

Add a Block > Choose Markdown

04.26c10v2 Header Sound Icon

Paste this code into Markdown Block

<script>
window.SCROLL_TOP_CONFIG = {
  selector: '.header-nav-item:nth-child(3)',
  href: '/services'
};
</script>
<script src="https://code.beaverhero.com/header/0526c15v2clickdropdowntitlescrolltop.js"></script>

05.26c15v2 Click Dropdown Scroll to top of page

Buy me a coffee