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. Scroll to Anchor on Same Page

Scroll to Anchor on Same Page

Scheduled Pinned Locked Moved General Discussion
5 Posts 2 Posters 1.6k 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.
  • edgrbnzE
    edgrbnzE
    edgrbnz
    wrote on last edited by edgrbnz
    #1

    Hi everyone,

    I’m right now helping out a colleague with his one page layout in LayTheme. He loves it!

    Since it’s a one-pager he wanted to have a “about” in the menu and make that scroll down to the section with the respective anchor.
    We already setup everything following this topic:
    http://laythemeforum.com/topic/2863/link-to-anchor-from-another-page/4

    So it’s all working now when the user visits http://tldomain.com#about the site loads and then smoothly scrolls down to the anchor. But when the user is on the front page and clicks on the about link in the menu the hole page just snaps to the anchor point w/o any smooth sroll transition.

    <script>
        window.laytheme.on('newpageshown', function(){
           if(window.location.hash.length > 0){
               var id = window.location.hash;
               if(jQuery(id).length > 0){
                    jQuery('html, body').animate(
                    { scrollTop: jQuery(id).offset().top },
                    { duration: 1200 });
               }
           } 
        });
    </script>
    

    I'm sorry if this has been solved already somewhere in the forum. I was unable to find a good solution, though.

    Any help is very much appreciated!

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

      Dear @edgrbnz
      the code you show us here does the following:

      • see if there is a # in the url
      • scroll to the id behind the #
      • animate the scrolling

      It is not for when you click on a link.
      You need another function for this.

      I have those two threads bookmarked. I hope you can find a solution there.

      ANCHOR LINK
      http://laythemeforum.com/topic/2863/link-to-anchor-from-another-page/4

      SMOOTH LINK
      http://laythemeforum.com/topic/2144/fade-effect-smooth-transitions-links-via-custom-html/2

      Otherwise let us know.

      Best!

      Marius

      www.mariusjopen.world

      1 Reply Last reply
      0
      • edgrbnzE
        edgrbnzE
        edgrbnz
        wrote on last edited by edgrbnz
        #3

        Well!

        I just added

        html {
          scroll-behavior: smooth;
        }
        

        which does the trick. But it doesn’t get recognized by laytheme’s Custom CSS section to be valid code. It says: Unknown property: scroll-behavior. It works!

        1 Reply Last reply
        0
        • edgrbnzE
          edgrbnzE
          edgrbnz
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • mariusjopenM
            mariusjopenM
            mariusjopen
            Global Moderator
            wrote on last edited by
            #5

            Dear @edgrbnz
            ah great! Thank you for sharing.

            Yes, even though things do not get recognized – they get recognized :-)

            Best!

            Marius

            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
            ffingerF
            ffinger
            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