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. smooth scrolling to anchor not working

smooth scrolling to anchor not working

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

    Hello, I'm trying to figure out how to make a custom link in a menu make a smooth scroll to an anchor on the same page, it's driving me nuts at this point tbh :D It always just jumps to the anchor with what seems to be a reload of the page but not with a smooth scroll.
    My setup is: I have custom links in a menu (www.mysite.com/#tag) and I have given some elements on the page an ID, I also declared their class as "anchor".
    I tried using the code from these threads (and many more), but nothing worked:

    http://laythemeforum.com/topic/2863/link-to-anchor-from-another-page
    http://laythemeforum.com/topic/7463/scroll-behavior-smooth
    http://laythemeforum.com/topic/4200/definitive-guide-to-smooth-scroll-to-anchors-from-menu

    As I have basically no coding knowledge, I can't really figure out what I am doing wrong currently, so help would be greatly appreciated

    1 Reply Last reply
    0
    • P
      P
      person5
      wrote on last edited by person5
      #2

      So I just made a simple test page (https://lukasrabl.com/test/) and the scroll animation is working perfectly fine there, using this Jquery code:

      <script>
          
      jQuery(document).ready(function(){
      	jQuery('body').on('click', '.js-scrollTo', function(event) {
      		event.preventDefault();
      		var id = jQuery(this).attr('href');
      		jQuery('html, body').animate( { scrollTop: jQuery(id).offset().top }, 750 );
      	});
      })
      
      
      </script>
      

      The links I used were in elements on the page itself, like in a text box. But when I use links in the menu to scroll to different parts, it doesn't work. So maybe the error is somewhere there?

      1 Reply Last reply
      0
      • P
        P
        person5
        wrote on last edited by person5
        #3

        I fixed it, it was just because my links had a slash before the #hashtag.

        So I wrote www.mysite.com#tag instead of www.mysite.com/#tag and it worked immediately.

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

          hey dont use custom jquery code for smooth scroll animation

          the smooth scroll is already active by default

          just follow this tutorial and you're good to go:
          https://laytheme.com/documentation/jump-to-anchor.html

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