Scrolling 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.

Who Can Use It

Partners who have already integrated Site Builder.

How to Get It

  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:

<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.

Here is the tutorial video for this recipe: