Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • 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 280 Views 2 Watching
  • 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
    dmncnD
    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
      arminunruhA
      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
        arminunruhA
        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
          dmncnD
          dmncn
          wrote on last edited by
          #4

          Now it works, thank you!

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

            Great to hear!

            www.mariusjopen.world

            1 Reply Last reply
            0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            Online Users
            OLVVDBO
            OLVVDB
            L
            lstark
            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