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

Scroll to anchor on another page

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

    Hi all, I have a question:
    I have one overview page with various projects, one project per row. Now when somebody is on a project subpage a link from there should go back to the overview page and then smooth scroll to the row with the project he was before.

    I gave all rows on overview page a unique id and the link on the subpage to get back is like href="www.domain.com/overviewpage/#id". Now I need a script for anchor and smooth scroll, right? Can somebody help? All threads regarding scrolling to anchors here in the forum couldn't solve the problem.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maximilianm
      wrote on last edited by
      #2

      This here at custom head content results in a
      TypeError: undefined is not an object (evaluating '$(target).offset().top')

      <script>
      jQuery(document).ready(function($){
          var jump=function(e)
      {
         if (e){
             e.preventDefault();
             var target = $(this).attr("href");
         }else{
             var target = location.hash;
         }
      
         $('html,body').animate(
         {
             scrollTop: $(target).offset().top
         },2000,function()
         {
             location.hash = target;
         });
      
      }
      
      $('html, body').hide();
      
      $(document).ready(function()
      {
          $('a[href^="#"]').bind("click", jump);
      
          if (location.hash){
              setTimeout(function(){
                  $('html, body').scrollTop(0).show();
                  jump();
              }, 0);
          }else{
              $('html, body').show();
          }
      });
      });
      </script>
      
      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximilianm
        wrote on last edited by
        #3

        Or maybe it's because how Laytheme handles links with anchors?

        When I enter
        http://domain.com/page#anchor
        it's changed to
        http://domain.com/page/anchor

        It only works correct when I'm already on the page, where the anchor is.

        1 Reply Last reply
        0
        • DMBD Offline
          DMBD Offline
          DMB
          wrote on last edited by
          #4

          Hey man, I figured this out last week but then ended up not using the smooth scroll!

          So in custom head content put this:

          <!--SMOOTH SCROLL ANCHOR POINTS-->

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

          So obviously you need to replace 'yourclasshere' with your own class name.

          What I was using this script for was for several text links at the top of the page which would just scroll down to a certain point underneath where each image was.

          In that case I assigned the point I wanted to arrive at an #id and then in the text editor using the 'link' button entered this id '#youridhere'.

          I then had to go into the html editor in the text editor and manually add in the class in my JS script before the href link.

          That way all my anchors were smooth scrolling.

          I'm not entirely clear what you want to smooth scroll but hope you can adapt my code :)

          Best,

          Duncan

          M 1 Reply Last reply
          1
          • DMBD DMB

            Hey man, I figured this out last week but then ended up not using the smooth scroll!

            So in custom head content put this:

            <!--SMOOTH SCROLL ANCHOR POINTS-->

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

            So obviously you need to replace 'yourclasshere' with your own class name.

            What I was using this script for was for several text links at the top of the page which would just scroll down to a certain point underneath where each image was.

            In that case I assigned the point I wanted to arrive at an #id and then in the text editor using the 'link' button entered this id '#youridhere'.

            I then had to go into the html editor in the text editor and manually add in the class in my JS script before the href link.

            That way all my anchors were smooth scrolling.

            I'm not entirely clear what you want to smooth scroll but hope you can adapt my code :)

            Best,

            Duncan

            M Offline
            M Offline
            maximilianm
            wrote on last edited by
            #5

            @DMB
            Nice one thanks!

            Will check it out asap, though I don't think it works in my case as my links refer to another page (not the same as anchor) so I'm not sure if the script works.

            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