Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Anchor link not scrolling


chichi

Question

Hi I added an anchor link the main landing page. The link goes to the right place but instead of scrolling down it looks like it's jumping to another page. How can I do "scroll down" effect?

It's the main page button "Get started"

www.personalchefberlin.de

password: june

 

Link to post
  • Answers 5
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

5 answers to this question

Recommended Posts

  • 0

@chichi Add the following javascript code below.

Features:

  • Targets all anchor links on the page
  • Update the SPEED variable in the javascript code if you want to adjust the speed of the scroll. The value needs to be a number in milliseconds. The default is set to 300 milliseconds

JavaScript

(function (window, document) {

  // Speed in milliseconds.
  var SPEED = 300;

  /**************************************************************
   * DO NOT MODIFY CODE BELOW, unless you know what you're doing
   **************************************************************/

  // Execute code based loading of the page
  if (document.readyState == 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }

  // Check if smooth scrolling library has been loaded. If so, then
  // enable all anchor links to scroll smoothly.
  function init() {
    // Create script to load smooth scroll libary if it's not already loaded:
    // https://github.com/cferdinandi/smooth-scroll
    if (!window.SmoothScroll) {
      var s = document.createElement('script');
      s.src = 'https://cdnjs.cloudflare.com/ajax/libs/smooth-scroll/16.1.3/smooth-scroll.min.js';
      s.addEventListener('load', smoothScrollInit);
      document.body.appendChild(s);
    }  else {
      smoothScrollInit();
    }

    function smoothScrollInit(){
      var scroll = new SmoothScroll('a[href*="#"]', {
        speed: SPEED || 300
      });
    }
  }
})(window, document);

Be sure to place the script between <script> tags, example:

<script>
  // Add JS code here
</script>

See article on how to add javascript: https://support.squarespace.com/hc/en-us/articles/205815928-Adding-custom-HTML-CSS-and-JavaScript

Edited by jpeter
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...