Skip to main content
When Usertour shows a tooltip that points to an element outside the current viewport, it needs to scroll that element into view. This method lets you take control of exactly how that scrolling happens. By default, Usertour leaves a target that is already in view where it is; otherwise it smooth-scrolls the target to the center of the viewport, or brings it in by its top when it is taller than the viewport. If all you need is to keep a fixed header or bar clear, use setScrollPadding() instead. But maybe you want different behavior—like only scrolling as far as needed, or using a custom scroll animation library. That’s what setCustomScrollIntoView() is for.

When to use

  • You want to customize the scroll behavior when Usertour shows tooltips or highlights elements
  • You need to integrate with a custom scroll library or animation framework
  • You want different positioning (e.g., always center elements vertically instead of just bringing them into view)
  • Your app has custom scroll containers or non-standard scrolling behavior

Parameters

function | null
required
A function that receives a DOM element and handles scrolling it into view. The function should perform whatever scroll logic you want. Pass null to reset to Usertour’s default scroll behavior.

Examples

Always center elements vertically

Maybe you want tooltip targets to always appear in the vertical center of the viewport for a consistent experience:
This ensures every highlighted element appears right in the middle of the screen, rather than just barely in view.

Using a custom scroll library

If you’re using a scroll animation library, you can integrate it here:

Reset to default behavior

If you want to go back to Usertour’s built-in scrolling:

Compare with default behavior

For reference, here’s roughly what Usertour does by default:
A target already in view is left alone; one that fits is centered; a taller one is brought in by its top, so the user starts at the beginning of it.

Notes

  • Call this method early in your initialization, ideally right after usertour.init()
  • Your custom function should handle the actual scrolling—Usertour won’t do any additional scrolling after calling your function
  • The element passed to your function is always the DOM element that Usertour wants to highlight or point to
  • If your scroll function is async or takes time, Usertour will continue immediately—make sure your timing works well with tooltip animations
  • Consider viewport padding and navigation bars when implementing custom scroll logic. While a callback is set, setScrollPadding() is not used
  • Test with elements at different viewport positions to ensure consistent behavior