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. Link to Anchor from another page

Link to Anchor from another page

Scheduled Pinned Locked Moved General Discussion
24 Posts 7 Posters 4.2k 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.
  • mariusjopenM mariusjopen

    Dear @pmpm
    can you post the JS code which you use?

    Best!

    Marius

    P Offline
    P Offline
    pmpm
    wrote on last edited by
    #21

    @mariusjopen straight out of the youtube tutorial:

    <script>
        
        jQuery(document).on( 'click', 'a[href^="#"]', function(e){
            e.preventDefault();
            var hash = jQuery(this).attr('href');
            var el = jQuery(hash);
            var top = el.offset().top;
            jQuery('html, body').animate({
                scrollTop: top
            }, 1200, 'swing',
                function() {
                    window.location.hash = hash;
                }
            );
        } );
        
        window.laytheme.on('newpageshown', function(){
            var hash = window.location.hash; 
            var el = jQuery(hash);
            if(el.length > 0) {
                var top = el.offset().top;
                window.scroll(0, top);        
            }
        });
        
    </script>
    
    1 Reply Last reply
    0
    • mariusjopenM Offline
      mariusjopenM Offline
      mariusjopen
      Global Moderator
      wrote on last edited by
      #22

      Dear @joeclarkx

      <script>
          
          jQuery(document).on( 'click', 'a[href^="#"]', function(e){
              e.preventDefault();
              var hash = jQuery(this).attr('href');
              var el = jQuery(hash);
              var top = el.offset().top+80;
              jQuery('html, body').animate({
                  scrollTop: top
              }, 1200, 'swing',
                  function() {
                      window.location.hash = hash;
                  }
              );
          } );
          
          window.laytheme.on('newpageshown', function(){
              var hash = window.location.hash; 
              var el = jQuery(hash);
              if(el.length > 0) {
                  var top = el.offset().top;
                  window.scroll(0, top);        
              }
          });
          
      </script>
      

      Best!

      Marius

      www.mariusjopen.world

      P 1 Reply Last reply
      0
      • mariusjopenM mariusjopen

        Dear @joeclarkx

        <script>
            
            jQuery(document).on( 'click', 'a[href^="#"]', function(e){
                e.preventDefault();
                var hash = jQuery(this).attr('href');
                var el = jQuery(hash);
                var top = el.offset().top+80;
                jQuery('html, body').animate({
                    scrollTop: top
                }, 1200, 'swing',
                    function() {
                        window.location.hash = hash;
                    }
                );
            } );
            
            window.laytheme.on('newpageshown', function(){
                var hash = window.location.hash; 
                var el = jQuery(hash);
                if(el.length > 0) {
                    var top = el.offset().top;
                    window.scroll(0, top);        
                }
            });
            
        </script>
        

        Best!

        Marius

        P Offline
        P Offline
        pmpm
        wrote on last edited by
        #23

        Dear @mariusjopen Thanks a lot! It turned out that the script didn't even apply. So now it also works without the js and I found a solution to come to the right position with an empty textfield which contains the id above the image. This works great. But only in Firefox and Chrome. In Safari it seems like the scroll-position is not identical with other browsers. Do you have any clue what the problem could be there?

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

          Dear @joeclarkx
          happy you managed!

          How can I see your anchor links in action?

          Best!
          Marius

          www.mariusjopen.world

          1 Reply Last reply
          0
          • S sofiapapa08 referenced this topic on
          • P person5 referenced this topic on
          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