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

Public

0

Moves image to top of 'classic' layout (on mobile) when using Elementor post widget

Added: 1 year ago

Last Updated: 1 year ago

If you are using the classic layout for Elementor post widget with the image set to left or right, you cannot change the position of the image on mobile. If you have an lengthy excerpt or title it loo...

Elementor

AI Verified

0

Elementor Repeater Field Comma Separated

Added: 5 months ago

Last Updated: 5 months ago

Elementor

Unverified

1

Change image on hover - Elementor

Added: 1 year ago

Last Updated: 9 months ago

JQuery code snippet that changes image on hover

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: 4 months ago

Last Updated: 4 months ago

Offset anchor menu links from the top of the page.

Elementor

Unverified

0

Elementor Anchor Link Scroll Offset

Added: 4 months ago

Last Updated: 4 months ago

Offset anchor menu links from the top of the page.

Elementor

AI Verified

0

Elementor Container Global Gutter Settings

Added: 5 months ago

Last Updated: 4 months ago

Adds custom global gutters to elementor containers.