Introduction
In interactive web applications, guiding users through new features or workflows is crucial for adoption and understanding. Shepherd.js is a popular library for creating guided tours. This post discusses how adding a backdrop blur effect can significantly improve user focus during these tours.
The Problem: Maintaining User Focus
When a Shepherd.js tour highlights a specific element, the surrounding page content can still be distracting. Users may inadvertently focus on elements outside the tour's intended target, leading to a less effective learning experience. The goal is to minimize distractions and direct the user's attention solely to the highlighted element.
The Solution: Implementing a Backdrop Blur
A backdrop blur effect can be implemented by inserting a full-screen div element behind the Shepherd.js tour's SVG overlay. This blurred layer dims and softens the surrounding content, effectively creating a visual spotlight on the tour's current step. The highlighted target element is then brought to the foreground using a high z-index to ensure it remains crisp and clear.
Here's an illustrative example of how to add the backdrop filter in JavaScript:
function addBackdropBlur() {
const backdrop = document.createElement('div');
backdrop.style.cssText = `
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(5px);
z-index: 9999;
`;
backdrop.id = 'shepherd-backdrop';
document.body.appendChild(backdrop);
}
function removeBackdropBlur() {
const backdrop = document.getElementById('shepherd-backdrop');
if (backdrop) {
backdrop.remove();
}
}
// Call addBackdropBlur when the tour starts
// Call removeBackdropBlur when the tour ends
This code creates a full-screen div with a semi-transparent black background and a blur effect applied using backdrop-filter: blur(5px). The z-index ensures it sits behind the tour's highlighted element.
Benefits of Backdrop Blur
- Enhanced Focus: By visually dimming the surrounding content, users can concentrate on the specific element the tour is highlighting.
- Improved User Experience: The tour feels more polished and professional, leading to a better overall user experience.
- Increased Comprehension: Reducing distractions helps users better understand the purpose and function of the highlighted element.
Getting Started
- Identify the events in your Shepherd.js tour where you can inject and remove the backdrop.
- Create a
divelement with the appropriate styles for the blur effect. - Append this
divto the document body when the tour starts or a new step begins. - Remove the
divwhen the tour ends or the step changes.
Key Insight
Subtle visual cues, like a backdrop blur, can significantly impact user focus and comprehension during guided tours. By minimizing distractions, you create a more effective and engaging learning experience.
Top comments (0)