Smooth Scrolling (Elementor Sticky Header + Admin Bar Supported)

				
					/**
 * Smooth Scrolling (Elementor Sticky Header + Admin Bar Supported)
 * 
 * Version: 1.1
 */
( function( $ ) {
	let smoothScroll = function( hash ) {
		if ( ! $( hash ).length ) {
			return;
		}

		let position = $( hash ).offset().top - $( '#header' ).height();
		if ( $( 'body' ).hasClass( 'admin-bar' ) ) {
			let viewportWidth = $( window ).width();
			if ( viewportWidth > 782 ) {
				position -= 32;
			} else if ( viewportWidth > 600 ) {
				position -= 46;
			}
		}
		$( 'html, body' ).animate({
			scrollTop: position,
		}, 1000);
	}

	$( window ).on( 'elementor/frontend/init', function() {
		/** On load */
		let hash = window.location.hash;
		if ( $( hash ).size() ) {
			smoothScroll( hash );
		}

		/** For hash links */
		$( 'a[href^="#"]' ).on( 'click', function( event ) {
			smoothScroll( $( this ).attr('href') );
		} );		
	} );
} )( jQuery );
				
			

Powered by BetterDocs

Newsletter

Subscribe and stay connected through our Newsletter. We send out important news, tips and special offers.

  • This field is for validation purposes and should be left unchanged.