Lightweight Vanilla JS Library for Interactive Guided Tours – Boarding.js
It allows you to build step-by-step product introductions, dim the background to focus on specific UI elements.
prepareElement callback and preventMove API.1. Install Boarding.js with package managers.
# Yarn $ yarn add boarding.js # NPM $ npm install boarding.js
2. Import the library and required CSS:
// Import the core library
import { Boarding } from "boarding.js";
// Import base styles required for overlay and positioning
import "boarding.js/styles/main.css";
// Optionally import the basic theme for styled popovers
import "boarding.js/styles/themes/basic.css"; 3. For CDN usage without a build system:
<!-- Required base styles for overlay functionality --> <link rel="stylesheet" href="https://unpkg.com/boarding.js/styles/main.css" /> <!-- Optional theme for default popover styling --> <link rel="stylesheet" href="https://unpkg.com/boarding.js/styles/themes/basic.css" />
<script type="module">
import { Boarding } from "https://unpkg.com/boarding.js/dist/main.js";
</script> 4. Highlight a single page element by passing its CSS selector. This works well for drawing attention to new features or guiding users to specific actions.
// Initialize Boarding instance
const boarding = new Boarding();
// Highlight element with ID "action"
boarding.highlight("#action"); 5. Add descriptive content alongside highlighted elements:
boarding.highlight({
element: "#cta",
popover: {
title: "CTA Title", // Accepts plain text or HTML
description: "CTA Description", // Accepts plain text or HTML
},
}); 6. To create a multi-step guided tour, define an array of steps, and the library will take care of the rest.
Step Definition Options:
string | Node – Query selector string or DOM Node to be highlighted.object – Configuration for the popover (see below).() => {} – Called before moving to this step. Useful for setup logic.(Element) => {} – Overwrite the global onNext handler for this specific step.(Element) => {} – Overwrite the global onPrevious handler for this specific step.(Element) => {} – Overwrite the global handler.(Element) => {} – Overwrite the global handler.(Element) => {} – Overwrite the global handler.Popover Object Properties:
string – Additional class for this specific popover.string – Title text (supports HTML).string – Body text (supports HTML).boolean – Toggle footer buttons for this step.string – Custom text for the done button.string – Custom text for the close button.string – Custom text for the next button.string – Custom text for the previous button."top" | "right" | "bottom" | "left" – Preferred side to render the popover."start" | "center" | "end" – Alignment of the popover relative to the side.number – Pixel offset from the element.(el) => {} – Hook for direct DOM manipulation of the popover.// Define array of step objects
boarding.defineSteps([
{
element: "#element-one",
popover: {
// Custom CSS class for styling this specific step
className: "element-one",
title: "Element 1",
description: "Description 1",
preferredSide: "left",
},
},
{
element: "#element-two",
popover: {
title: "Element 2",
description: "Description 2",
preferredSide: "top",
},
// OPTIONAL
onNext: () => {
// Stop automatic progression to next step
boarding.preventMove();
// Execute async operation (API call, animation, etc.)
setTimeout(() => {
// Resume tour after operation completes
boarding.continue();
}, 3000);
},
},
{
element: "#element-three",
popover: {
title: "Element 3",
description: "Description 3",
preferredSide: "right",
},
},
// more steps here
]);
// Start the tour
boarding.start(); 7. All configuration options.
string – Class name to wrap the popover.boolean – Whether to animate transitions. Default is true.number – Overlay opacity (0 means only popovers are visible without the dark overlay). Default is 0.75.number – Distance of the highlight area from the element edges. Default is 10.boolean – Whether clicking the overlay closes the tour. Default is true.boolean – Whether clicking the overlay moves to the next step. Default is false.string – Fill color for the overlay. Default is "rgb(0,0,0)".string – Text on the final button. Default is "Done".string – Text on the close button. Default is "Close".string – Text on the next button. Default is "Next".string – Text on the previous button. Default is "Previous".boolean – Whether to show control buttons in the footer. Default is false.boolean – Allow controlling through keyboard (Escape to close, Arrow keys to move). Default is true.object – Options passed to the native scrollIntoView(). Default includes { behaviour: "smooth" }. Set to "no-scroll" to disable.boolean | "block-all" – Controls pointer events. true allows clicks only on the highlighted element. "block-all" blocks all events.(HighlightElement) => {} – Called when an element is about to be highlighted.(HighlightElement) => {} – Called when an element is fully highlighted.(HighlightElement) => {} – Called when an element has been deselected.(HighlightElement) => {} – Called when the overlay is about to be cleared.(HighlightElement) => {} – Called when boarding.start() is triggered.(HighlightElement) => {} – Called when moving to the next step.(HighlightElement) => {} – Called when moving to the previous step.(el) => {} – Hook to manipulate popover elements after rendering.const boarding = new Boarding({
className: "scoped-class",
animate: true,
opacity: 0.75,
padding: 10,
allowClose: true,
overlayClickNext: false,
overlayColor: "rgb(0,0,0)",
doneBtnText: "Done",
closeBtnText: "Close",
nextBtnText: "Next
prevBtnText: "Previous",
showButtons: false,
keyboardControl: true,
scrollIntoViewOptions: {
behaviour: "smooth",
},
onBeforeHighlighted: (HighlightElement) => {},
onHighlighted: (HighlightElement) => {},
onDeselected: (HighlightElement) => {},
onReset: (HighlightElement) => {},
onStart: (HighlightElement) => {},
onNext: (HighlightElement) => {},
onPrevious: (HighlightElement) => {},
strictClickHandling: true,
onPopoverRender: (el) => {},
}); 8. API methods.
true if a next step exists.true if a previous step exists.preventMove.true to skip animations.true if an element is currently highlighted.HighlightElement instance.Q: How do I prevent users from clicking elements outside the tour during onboarding?
A: Set the strictClickHandling option to true or “block-all” when initializing Boarding. The true setting allows clicks only on the highlighted element while “block-all” prevents all interactions except with the popover itself.
Q: Can I use Boarding.js with React or Vue single-page applications where elements mount asynchronously?
A: Yes. Define steps with selectors for elements that do not yet exist in the DOM. Boarding.js polls for these elements using MutationObserver and begins the step once they mount.
Q: What happens if a tour step targets an element that gets removed from the DOM during the tour?
A: The tour will skip that step automatically if the element no longer exists when Boarding tries to highlight it.
Q: How do I integrate Boarding.js with my existing analytics system to track tour completion rates?
A: Use the lifecycle callbacks to send tracking events. The onStart callback fires when a tour begins, onNext and onPrevious track navigation, and onReset indicates when users exit the tour early. You can also check hasNextStep in your onNext callback to identify the final step and track completions separately from early exits.
Q: Why does my popover appear in the wrong position on mobile devices?
A: Mobile browsers often have dynamic viewport heights due to address bars that hide on scroll. Ensure your scrollIntoViewOptions properly account for this by testing with different scroll positions. You can also increase the offset value to provide more breathing room between the element and popover on smaller screens.
The post Lightweight Vanilla JS Library for Interactive Guided Tours – Boarding.js appeared first on CSS Script.
The AI Workmate Concept can move and rotate to accomplish various tasks, but can it…
The magnetic pen case is pulling wedge duty in there. Lenovo has a few new…
We’ve been waiting five years for this follow-up to the X12 Detachable. | Image: Lenovo…
TAYLOR COUNTY, Texas (KTAB/KRBC) - A two-vehicle collision occurred south of Abilene Sunday afternoon. The…
Scream 7 has enjoyed a huge box office opening weekend, with nearly $100 million secured…
Another month has ended, and we are now officially in March! Today, there are quite…
This website uses cookies.