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 w/ anchors

Scroll w/ anchors

Scheduled Pinned Locked Moved General Discussion
6 Posts 2 Posters 187 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.
  • D Offline
    D Offline
    Diagonal
    wrote on last edited by
    #1

    Hi there!

    I'm trying to add a scroll effect using anchor points. It actually works, the only thing is I'd like the block not to display on top, but in a lower position (80px, just the menu height).

    Here's the code I'm using, I guess it should be kind of easy but I have no coding skills at all :/

    Can anybody help? Thanks in advance!

    <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
        }, 300, '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);        
        }
    });
    
    D 1 Reply Last reply
    0
    • D Diagonal

      Hi there!

      I'm trying to add a scroll effect using anchor points. It actually works, the only thing is I'd like the block not to display on top, but in a lower position (80px, just the menu height).

      Here's the code I'm using, I guess it should be kind of easy but I have no coding skills at all :/

      Can anybody help? Thanks in advance!

      <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
          }, 300, '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);        
          }
      });
      
      D Offline
      D Offline
      Diagonal
      wrote on last edited by
      #2

      Here's the site I'm working on in case it helps :)

      http://www.metal-horns.co/resist

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

        Dear @Diagonal
        what should happen when you click where?

        Best!

        Marius

        www.mariusjopen.world

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Diagonal
          wrote on last edited by
          #4

          Hi Marius!

          Sorry for the awkward explanation, and thank you for this awesome theme! I'm using this Laytheme option:

          Cover options > Scroll down on Cover click āœ…

          Works smooth, but the text is hidden by the bar menu. I tried to solve it with anchors and some code, but I have no coding skills at all...

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Diagonal
            wrote on last edited by
            #5

            UPDATE: I managed to make it work with anchor navigation and custom code! The bad news: after the scroll effect, the browser URL adds a #hash at the end (the anchor). To prevent poor user experience, I'd need to remove it from the browser URL bar, as an extra click is required in the back button to actually go back a page.

            I've realized no #hash is added when using the "scroll down on cover" option, so I guess that would do the job ... but I still have no idea how can I change the ".top" value to a different position. I don't want to add no margin or padding to keep the layout as it is in case the user doesn't click over the cover image.

            Note: I wouldn't mind AT ALL if the "back to top" jumps to the text block instead of the hero image, just in case :)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Diagonal
              wrote on last edited by
              #6

              Hi there! I've been trying so hard, but I'm not able to solve it :/
              I gave up the anchor navigation, as I've read it's not possible... so I guess the only solution would be using the "Scroll down on Cover click" and change somehow the top position. Please help!

              http://www.metal-horns.co/resist-2

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