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

smooth scrolling to anchor not working

Scheduled Pinned Locked Moved General Discussion
4 Posts 2 Posters 552 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.
  • P Offline
    P Offline
    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:4567/topic/2863/link-to-anchor-from-another-page
    http://laythemeforum.com:4567/topic/7463/scroll-behavior-smooth
    http://laythemeforum.com:4567/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 Offline
      P Offline
      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 Offline
        P Offline
        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 Offline
          arminunruhA Offline
          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
          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
          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