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

Scroll to Anchor on Same Page

Scheduled Pinned Locked Moved General Discussion
5 Posts 2 Posters 1.4k 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 Offline
    edgrbnzE Offline
    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:4567/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 Offline
      mariusjopenM Offline
      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:4567/topic/2863/link-to-anchor-from-another-page/4

      SMOOTH LINK
      http://laythemeforum.com:4567/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 Offline
        edgrbnzE Offline
        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 Offline
          edgrbnzE Offline
          edgrbnz
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • mariusjopenM Offline
            mariusjopenM Offline
            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
            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
            arminunruhA
            arminunruh
            A
            alasdair17
            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