How to allow users scroll the page to the specified block

How it works

If you want to draw users’ attention to a particular block of your site, you can set up automatic scrolling to this block via a custom HTML code. You may use an existing solution or write your own code.

How to get it

Using an existing solution

  1. Go to Publisher Account > Site Builder.
  2. Add the Button component to the block where the scrolling should begin. Change your button text.
  3. Set the component type to Link and insert any link into the field.
  4. Insert the following code to the Custom code block:

Copy
Full screen
Small screen
<script>
(function() {
var scrollBlock = '.block--header';
var scrollBlockNumber = 0;
var scrollButtonNumber = 0;

var scrollToBlockName = '.block--packs';
var scrollToBlockNumber = 0;

var button = document.querySelectorAll(scrollBlock)[scrollBlockNumber].querySelectorAll('.ui-site-calltoaction--link')[scrollButtonNumber];
button.href = 'javascript:void(0)';
button.addEventListener('click', function () {
  var scrollTo = document.querySelectorAll(scrollToBlockName)[scrollToBlockNumber];
  scrollTo.scrollIntoView({ behavior: 'smooth' });
});
})();
</script>

  1. Modify the following parameters:
    1. scrollBlock — the name of the CSS class of the block that contains the scroll button. Possible options are:
      • .block--header (the Header block)
      • .block--hero (the Call to action block)
      • .block--packs (the Packs block)
    2. scrollBlockNumber — the sequence number of the block that contains the scroll button. Minimum value is 0.
    3. scrollButtonNumber — the sequence number of the scroll button. Minimum value is 0.
    4. scrollToBlockName — the name of the CSS class of the block to scroll the page to. Possible options are:
      • .block--header (the Header block)
      • .block--hero (the Call to action block)
      • .block--html (the Custom code block)
      • .block--packs (the Packs block)
      • .block--description (the Description block)
      • .block--gallery (the Gallery block)
      • .block--requirements (the System requirements block)
      • .block--faq (the FAQ block)
      • .block--embed (the Social media widgets block)
      • .block--news (the News block)
      • .block--footer (the Footer block)
    5. scrollToBlockNumber — the sequence number of the block to scroll the page to. Minimum value is 0.

  1. Click Preview to see your changes.

Watch the tutorial video for this instruction:


Writing your own code

If you want to use your own code:

  1. Go to Publisher Account > Site Builder.
  2. Insert the code to the Custom code block.
  3. Click Preview to see your changes.

Was this article helpful?
Thank you!
Is there anything we can improve? Message
We're sorry to hear that
Please explain why this article wasn't helpful to you. Message
Thank you for your feedback!
We'll review your message and use it to help us improve your experience.

Continue reading