Skip to main content
When a tooltip points to an element outside the viewport, Usertour scrolls that element into view. If your app has a fixed header or a fixed bottom bar, the element can end up underneath it. setScrollPadding() tells Usertour how many pixels to keep clear at each edge of the page, so the element lands in the part the user can actually see.

Parameters

object | null
required
The pixels to keep clear at each edge. Every side is optional and defaults to 0. Pass null to clear the padding.

Examples

Keep a fixed header clear

A fixed header and a fixed bottom bar

Clear the padding

How the default scroll works

  • A target that can already be seen whole, clear of the padding, is left where it is: the page doesn’t move.
  • Otherwise, a target that fits in the visible part of the page (the viewport minus the padding) is centered in it.
  • A target taller than that, such as a long table, is scrolled in by its top, so the user starts at the beginning of it rather than in the middle.
  • The padding applies when the page itself scrolls to the target. An element that has to be scrolled inside a scrolling container or an iframe is scrolled into view the browser’s way, and the padding does not decide where it lands. For such pages, set CSS scroll-padding on your page’s html element instead.
  • If your page also sets a CSS scroll-padding on its html element, the setScrollPadding() value is the one used when the page itself scrolls to the target; the CSS value is not added to it. Pass the full amount you want kept clear. Without setScrollPadding(), the browser does the scroll and keeps your CSS scroll-padding clear.
  • A padding with no positive side, such as { top: 0 }, is the same as null: the browser does the scroll and keeps your CSS scroll-padding clear. setScrollPadding() can’t be used to turn a CSS scroll-padding off.
  • Usertour never changes your page’s styles.

Notes

  • You can call it before usertour.init(), or before the script has loaded; the call is applied when the SDK loads. Queuing it before load needs the current installation snippet or the usertour.js npm package v0.0.28 or newer; an older snippet drops that early call with a warning, so call it again after the SDK has loaded or update the snippet.
  • When a setCustomScrollIntoView() callback is set, your callback does the scrolling and the padding is not used.
  • Needs Usertour.js newer than v0.9.9. Usertour Cloud always serves the newest version; self-hosted, upgrade your server. An older version ignores the call and logs a warning.