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
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-paddingon your page’shtmlelement instead. - If your page also sets a CSS
scroll-paddingon itshtmlelement, thesetScrollPadding()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. WithoutsetScrollPadding(), the browser does the scroll and keeps your CSSscroll-paddingclear. - A padding with no positive side, such as
{ top: 0 }, is the same asnull: the browser does the scroll and keeps your CSSscroll-paddingclear.setScrollPadding()can’t be used to turn a CSSscroll-paddingoff. - 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 theusertour.jsnpm 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.