Driver.js
Powerful yet light-weight, vanilla JavaScript engine to drive the user's focus across the page
Only ~4kb, no external dependency, supports all major browsers and highly customizable
- Simple: is simple to use and has no external dependency at all
- Light-weight: ~4kb in size, vanilla JavaScript and no external dependency
- Highly customizable: has a powerful API and can be used however you want
- Highlight anything: highlight any (literally any) element on page
- Feature introductions: create powerful feature introductions for your web applications
- Focus shifters: add focus shifters for users
- User friendly: Everything is controllable by keyboard
- Consistent behavior: usable across all browsers (including in-famous IE)
- MIT Licensed: free for personal and commercial use
For Usage and Examples, have a look at demo
So, yet another tour library?
No it is not. Tours are just one of the many use-cases. Driver.js can be used at any place where you need some sort of overlay for the page, some common usecases could be e.g. dimming the background when user is interacting with some component i.e. the way Facebook does when you try to create a post, or you can use it as a focus shifter to bring user's attention to some component on page or maybe you can use it to simulate those "Turn off the Lights" widgets that you might have seen on video players online etc.
Driver.js is written in Vanilla JS, has zero dependencies and is highly customizable. It has several options allowing you to manipulate how it behaves and also provides you the hooks to manipulate the elements as they are highlighted about to be highlighted or deselected.
Installation
You can install it using yarn
or npm
, whatever you prefer
yarn add driver.js
npm install driver.js
Or grab the code from dist
directory and include it directly
<link rel="stylesheet" href="/dist/driver.min.css">
<script src="/dist/driver.min.js"></script>
Usage and Demo
Demos and many more usage examples can be found through the docs page.
Highlighting Single Element – Demo
If all you want is just highlight a single element, you can do that simply by passing the selector
const driver = new Driver();
driver.highlight('#create-post');
A real world usage example for this could be using it to dim the background and highlight the required element e.g. the way facebook does it on creating a post.
Highlight and Popover – Demo
You can show additional details beside the highlighted element using the popover
const driver = new Driver();
driver.highlight({
element: '#some-element',
popover: {
title: 'Title for the Popover',
description: 'Description for it',
}
});
Also, title
and description
can have HTML as well.
Positioning the Popover – Demo
By default, driver automatically finds the suitable position for the popover and displays it, you can override it using position
property
const driver = new Driver();
driver.highlight({
element: '#some-element',
popover: {
title: 'Title for the Popover',
description: 'Description for it',
position: 'left',
}
});
Creating Feature Introductions – Demo
Feature introductions are helpful in onboarding new users and giving them idea about different parts of the application, you can create them seemlessly with driver. Define the steps and call the start
when you want to start presenting. User will be able to control the steps using keyboard or using the buttons on popovers.
const driver = new Driver();
driver.defineSteps([
{
element: '#first-element-introduction',
popover: {
title: 'Title on Popover',
description: 'Body of the popover',
position: 'left'
}
},
{
element: '#second-element-introduction',
popover: {
title: 'Title on Popover',
description: 'Body of the popover',
position: 'top'
}
},
{
element: '#third-element-introduction',
popover: {
title: 'Title on Popover',
description: 'Body of the popover',
position: 'right'
}
},
]);
driver.start();
You can also hide the buttons and control the introductions programmatically by using the API methods listed below
API
Driver comes with several options that you can manipulate to make driver behave as you may like
Driver Definition
Here are the options that Driver understands
const driver = new Driver({
animate: true,
opacity: 0.75,
padding: 10,
allowClose: true,
doneBtnText: 'Done',
closeBtnText: 'Close',
stageBackground: '#ffffff',
nextBtnText: 'Next',
prevBtnText: 'Previous',
showButtons: false,
scrollIntoViewOptions: {},
onHighlightStarted: (Element) {},
onHighlighted: (Element) {},
onDeselected: (Element) {},
});
Note that all the button options that you provide in the driver definition can be overridden for a specific step by giving them in the step definition
Step Definition
Here are the set of options that you can pass while defining steps defineSteps
or the object that you pass to highlight
method
const stepDefinition = {
element: '#some-item',
stageBackground: '#ffffff',
popover: {
title: 'Title',
description: 'Description',
showButtons: false,
doneBtnText: 'Done',
closeBtnText: 'Close',
nextBtnText: 'Next',
prevBtnText: 'Previous',
}
};
For example, here is how it would look when highlighting a single element
const driver = new Driver(driverOptions);
driver.highlight(stepDefinition);
And this is how it would look when creating a step by step guide
const driver = new Driver(driverOptions);
driver.defineSteps([
stepDefinition1,
stepDefinition2,
stepDefinition3,
stepDefinition4,
]);
API Methods
Below are the set of methods that are available to you
const driver = new Driver(driverOptions);
if (driver.isActivated) {
console.log('Driver is active');
}
driver.defineSteps([ stepDefinition1, stepDefinition2, stepDefinition3 ]);
driver.start(stepNumber = 0);
driver.moveNext();
driver.movePrevious();
driver.hasNextStep();
driver.hasPreviousStep();
driver.highlight(string|stepDefinition);
driver.reset();
driver.reset(clearImmediately = false);
if(driver.hasHighlightedElement()) {
console.log('There is an element highlighted');
}
const activeElement = driver.getHighlightedElement();
const lastActiveElement = driver.getLastHighlightedElement();
activeElement.getScreenCoordinates();
activeElement.hidePopover();
activeElement.showPopover();
activeElement.getNode();
Note – Do not forget to add e.stopPropagation()
to the click
binding that triggers driver
Todo
Contributions
Feel free to submit pull requests, create issues or spread the word
License
MIT © Kamran Ahmed