Unverified

Name

Elementor Anchor Link Scroll Offset

About

Offset anchor menu links from the top of the page.

Language

Javascript

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Set desktop, tablet, and mobile values to desired offset in PX

Codevault

Robert-Wattner's-Snippets

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

15/03/2024

Important Note

This snippet has the following status:

Unverified

This snippet has not been verified, use with caution and at your own risk. See details provided by author in sidebar and click below to find out more.

Elementor Anchor Link Scroll Offset

 
                    
1window.addEventListener('elementor/frontend/init', function() {
2 elementorFrontend.hooks.addFilter('frontend/handlers/menu_anchor/scroll_top_distance', function(scrollTop) {
3 // Get viewport width
4 var viewportWidth = window.innerWidth;
5 
6 // Define scroll top distances for different viewport widths
7 var desktop = 120; // Scroll top distance for desktop (viewport width >= 1025px)
8 var tablet = 100; // Scroll top distance for tablet (viewport width between 768px and 1024px)
9 var mobile = 80; // Scroll top distance for mobile (viewport width below 768px)
10 
11 // Define scroll top distance based on viewport width
12 if (viewportWidth >= 1025) {
13 // Desktop
14 return scrollTop - desktop;
15 } else if (viewportWidth >= 768 && viewportWidth <= 1024) {
16 // Tablet
17 return scrollTop - tablet;
18 } else {
19 // Mobile
20 return scrollTop - mobile;
21 }
22 });
23 });

0

Related Snippets

Please see some snippets below related to this snippet..

Elementor

Unverified

Elementor

Unverified

0

show youtube channel on wordpress

Added: 4 months ago

Last Updated: 4 months ago

Elementor

Unverified

0

Global Starter CSS

Added: 10 months ago

Last Updated: 9 months ago

My "normal" CSS Settings for a new site

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Elementor

AI Verified

0

Elementor Anchor Link Scroll Offset(PHP)

Added: 6 months ago

Last Updated: 6 months ago

Offset anchor menu links from the top of the page.

Elementor

Unverified

0

Elementor Anchor Link Scroll Offset

Added: 6 months ago

Last Updated: 6 months ago

Offset anchor menu links from the top of the page.

Elementor

AI Verified

0

Elementor Container Global Gutter Settings

Added: 6 months ago

Last Updated: 6 months ago

Adds custom global gutters to elementor containers.