1. HOT Divi Ultimate Header Plugin - More variety for your Divi header: https://header.diviultimate.com/

Solved Stop Divi offesetting Anchor links

Discussion in 'Free Divi Community Forum' started by David McDonagh, Jun 10, 2019.

  1. David McDonagh

    David McDonagh New Member

    Hi,

    I have a Divi site which uses a transparent fixed header. I have anchor links to sections in my menu.

    I would like the link to go to the top of the section, behind my transparent header. At the moment the section starts under the header with the bottom of the previous section visible behind my header. I would like the section to be at the top of the window.

    I have been searching for solutions for many hours now and had no luck. Usually it is the opposite problem people tend to have.

    Can anyone point me in the right direction?
     
    1. AD Add tons of new icons for your Divi site. Free version available: https://divi.help/link-forums/divi-icons-pro.147/
  2. Divi.Help

    Divi.Help Administrator
    Staff Member

    Try to add the below code in Divi > Theme Options > Integration > Body Code:
    Code:
    <script>
    jQuery(function($) {
           
        window.et_pb_smooth_scroll = function( $target, $top_section, speed, easing ) {
            var $window_width = $( window ).width();
    
            $menu_offset = -1;
    
            if ( $ ('#wpadminbar').length && $window_width > 600 ) {
                $menu_offset += $( '#wpadminbar' ).outerHeight();
            }
    
            //fix sidenav scroll to top
            if ( $top_section ) {
                $scroll_position = 0;
            } else {
                $scroll_position = $target.offset().top - $menu_offset;
            }
    
            // set swing (animate's scrollTop default) as default value
            if( typeof easing === 'undefined' ){
                easing = 'swing';
            }
    
            $( 'html, body' ).animate( { scrollTop :  $scroll_position }, speed, easing );
        }
       
    });
    </script>
     
    soulshakepower likes this.
  3. David McDonagh

    David McDonagh New Member

    Works like a charm. Thank you so much!!
     
    1. AD 50+ switches to fully customize your Divi website: https://divi.help/link-forums/divi-switch.162/
  4. Dick Ockers

    Dick Ockers New Member

    AND AGAIN! Thats what I was looking for. Thank you for sharing. Stay safe!
     
  5. soulshakepower

    soulshakepower New Member

    Thank you! I've been looking for this for a long time!

    Note: For it to work I had to enable the "Alternative scroll-to-anchor method" in divi>theme options>navigation>general.
    I've also changed the menu offset value to +110 to match my header size. Thanks!
     
    1. AD Set awesome default design for your Divi single blog page: https://blog.diviultimate.com/

Recommended Divi Hosting