Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Link to an anchor on a different page

Link to an anchor on a different page

Scheduled Pinned Locked Moved General Discussion
5 Posts 3 Posters 128 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • dmncnD Offline
    dmncnD Offline
    dmncn
    wrote on last edited by
    #1

    Hi,

    I’m not able to use anchors to scroll to a different sections of a page.

    I think the problem is that in the code there isn’t any element with the anchor name.

    I’ve tried to assign the ID to the row and to the element but it never shows in the html,

    The website is under development and I can provide the access to the admin panel.

    Thanks in advance

    1 Reply Last reply
    0
    • arminunruhA Offline
      arminunruhA Offline
      arminunruh
      Global Moderator
      wrote on last edited by
      #2

      do you link to a different page and then to an anchor on that different page?
      you can send the link to info@laytheme.com and please also send the url to this topic

      1 Reply Last reply
      0
      • arminunruhA Offline
        arminunruhA Offline
        arminunruh
        Global Moderator
        wrote on last edited by
        #3

        hey!

        ok, I inserted this code in "lay options"→ "Custom <head> content
        " and it works now:

        <script>
            //this is for making # links animate-scroll to a section that is on the same page
            jQuery(document).on( 'click', 'a[href^="#"]', function(e){
                e.preventDefault();
                var hash = jQuery(this).attr('href');
                var el = jQuery(hash);
                var top = el.offset().top;
                jQuery('html, body').animate({
                    scrollTop: top
                }, 300, 'swing',
                    function() {
                        window.location.hash = hash;
                    }
                );
            } );
            
           //this is for scrolling to a section of a different page when linking to it
            window.laytheme.on('newpageshown', function(){
                var hash = window.location.hash; 
                var el = jQuery(hash);
                if(el.length > 0) {
                    var top = el.offset().top;
                    window.scroll(0, top);        
                }
            });
            
        </script>
        
        1 Reply Last reply
        0
        • dmncnD Offline
          dmncnD Offline
          dmncn
          wrote on last edited by
          #4

          Now it works, thank you!

          1 Reply Last reply
          0
          • mariusjopenM Offline
            mariusjopenM Offline
            mariusjopen
            Global Moderator
            wrote on last edited by
            #5

            Great to hear!

            www.mariusjopen.world

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            I also code custom websites or custom Lay features.
            💿 Email me here: 💿
            info@laytheme.com

            Before you post:
            1. When using a WordPress Cache plugin, disable it or clear your cache.
            2. Update Lay Theme and all Lay Theme Addons
            3. Disable all Plugins
            4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

            This often solves issues you might run into

            When you post:
            1. Post a link to where the problem is
            2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
            3. If the problem is difficult to explain, post screenshots / link to a video to explain it
            Online Users
            C
            chrisboender
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
            laytheme.com
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Recent
            • Tags
            • Popular
            • Users
            • Search