Convert Figma logo to code with AI

kamranahmedse logodriver.js

A light-weight, no-dependency, vanilla JavaScript engine to drive user's focus across the page

22,354
1,006
22,354
77

Top Related Projects

JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)

13,501

Cross-browser QRCode generator for javascript

Quick Overview

Driver.js is a lightweight, no-dependency, vanilla JavaScript library that provides an easy way to create interactive walkthroughs and guides for your web applications. It allows you to highlight specific elements on the page, add tooltips, and guide users through a series of steps.

Pros

  • Lightweight and Dependency-free: Driver.js is a small library, weighing in at around 5KB (gzipped), and it doesn't require any external dependencies.
  • Customizable: The library provides a wide range of options and hooks to customize the appearance and behavior of the walkthroughs.
  • Cross-browser Compatibility: Driver.js works across all modern browsers, including IE11 and above.
  • Accessibility-focused: The library ensures that the walkthroughs are accessible to users with disabilities.

Cons

  • Limited Functionality: While Driver.js is great for creating simple walkthroughs, it may lack some advanced features that are available in other similar libraries.
  • Potential Performance Impact: Depending on the complexity of the walkthrough, the library may have a slight performance impact on the web application.
  • Lack of Animations: The library doesn't provide built-in animations, which may limit the visual appeal of the walkthroughs.
  • Limited Customization Options: While the library is customizable, the range of customization options may be limited compared to other similar libraries.

Code Examples

Here are a few examples of how to use Driver.js in your web application:

// Initialize the driver
const driver = new Driver();

// Define the steps for the walkthrough
driver.defineSteps([
  {
    element: '#feature-1',
    popover: {
      title: 'Feature 1',
      description: 'This is the first feature of our application.',
      position: 'top'
    }
  },
  {
    element: '#feature-2',
    popover: {
      title: 'Feature 2',
      description: 'This is the second feature of our application.',
      position: 'bottom'
    }
  }
]);

// Start the walkthrough
driver.start();
// Customize the appearance of the walkthrough
driver.setOptions({
  animate: true,
  opacity: 0.75,
  padding: 10,
  allowClose: true,
  overlayClickNext: true,
  doneBtnText: 'Finish',
  closeBtnText: 'Close',
  nextBtnText: 'Next',
  prevBtnText: 'Previous'
});
// Add event listeners to the driver
driver.on('start', () => {
  console.log('Walkthrough started');
});

driver.on('highlight', (highlightedStep) => {
  console.log('Highlighted step:', highlightedStep);
});

driver.on('finish', () => {
  console.log('Walkthrough finished');
});

Getting Started

To get started with Driver.js, follow these steps:

  1. Install the library using npm or yarn:
npm install driver.js
  1. Import the library and the CSS file in your project:
import Driver from 'driver.js';
import 'driver.js/dist/driver.min.css';
  1. Initialize the driver and define the steps for your walkthrough:
const driver = new Driver();

driver.defineSteps([
  {
    element: '#feature-1',
    popover: {
      title: 'Feature 1',
      description: 'This is the first feature of our application.',
      position: 'top'
    }
  },
  {
    element: '#feature-2',
    popover: {
      title: 'Feature 2',
      description: 'This is the second feature of our application.',
      position: 'bottom'
    }
  }
]);

driver.start();
  1. Customize the appearance and behavior of the walkthrough by setting options:
driver.setOptions({
  animate: true,
  opacity: 0.75,
  padding: 10,
  allowClose: true,
  overlayClickNext: true

Competitor Comparisons

JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)

Pros of Interact.js

  • Interact.js provides a more comprehensive set of features for handling user interactions, including support for touch events, gestures, and multi-touch.
  • The library has a larger and more active community, with more contributors and a more extensive documentation.
  • Interact.js is more flexible and customizable, allowing developers to create complex and interactive user interfaces.

Cons of Interact.js

  • Interact.js has a steeper learning curve compared to Driver.js, as it offers a wider range of features and a more complex API.
  • The library may be overkill for simple use cases, where Driver.js could provide a more lightweight and easier-to-use solution.

Code Comparison

Driver.js

const driver = new Driver({
  animate: true,
  opacity: 0.75,
  padding: 10,
  allowClose: true,
  overlayClickNext: true,
  doneBtnText: 'Finish',
  closeBtnText: 'Close',
  nextBtnText: 'Next',
  prevBtnText: 'Previous',
  showButtons: true,
  keyboardControl: true,
  onHighlightStarted: () => {},
  onHighlightCompleted: () => {},
  onNext: () => {},
  onPrevious: () => {},
  onClose: () => {}
});

driver.highlight({
  element: '#my-element',
  popover: {
    title: 'My Element',
    description: 'This is my element',
    position: 'left'
  }
});

Interact.js

interact('#draggable')
  .draggable({
    // enable inertial throwing
    inertia: true,
    // keep the element within the area of it's parent
    modifiers: [
      interact.modifiers.restrictRect({
        restriction: 'parent',
        endOnly: true
      })
    ],
    // enable autoScroll
    autoScroll: true,

    listeners: {
      // call this function on every dragmove event
      move: dragMoveListener,
      // call this function on every dragend event
      end: function (event) {
        var textEl = event.target.querySelector('p');

        textEl && (textEl.textContent =
          'moved a distance of ' +
          (Math.sqrt(Math.pow(event.pageX - event.x0, 2) +
                    Math.pow(event.pageY - event.y0, 2) | 0))
            .toFixed(2) + 'px');
      }
    }
  });

function dragMoveListener (event) {
  var target = event.target;
  // keep the dragged position in the data-x/data-y attributes
  var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
  var y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;

  // translate the element
  target.style.webkitTransform =
  target.style.transform =
    'translate(' + x + 'px, ' + y + 'px)';

  // update the posiion attributes
  target.setAttribute('data-x', x);
  target.setAttribute('data-y', y);
}
13,501

Cross-browser QRCode generator for javascript

Pros of QRCodeJS

  • Lightweight: QRCodeJS is a lightweight library, weighing in at around 10KB, making it suitable for use in web applications with limited resources.
  • Customizable: The library allows for customization of the QR code's appearance, including the ability to change the color and size of the code.
  • Cross-browser Compatibility: QRCodeJS is designed to work across a wide range of web browsers, ensuring consistent functionality for users.

Cons of QRCodeJS

  • Limited Functionality: Compared to Driver.js, QRCodeJS has a more limited set of features, focusing solely on QR code generation and not providing the broader set of UI/UX tools that Driver.js offers.
  • Lack of Active Maintenance: The QRCodeJS project has not been actively maintained in recent years, which may raise concerns about its long-term viability and support.

Code Comparison

Here's a brief comparison of the code for generating a simple QR code using QRCodeJS and creating a driver.js overlay using Driver.js:

QRCodeJS:

var qrcode = new QRCode("qrcode", {
  text: "https://example.com",
  width: 256,
  height: 256,
  colorDark: "#000000",
  colorLight: "#ffffff",
  correctLevel: QRCode.CorrectLevel.H
});

Driver.js:

const driver = new Driver({
  animate: true,
  opacity: 0.75,
  padding: 10,
  showButtons: true,
  showClose: true,
  showNextButton: true,
  showPrevButton: true,
  allowClose: true
});

driver.highlight({
  element: '#my-element',
  popover: {
    title: 'My Element',
    description: 'This is a description of my element.'
  }
});

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


Driver.js

version downloads

Powerful, highly customizable vanilla JavaScript engine to drive the user's focus across the page
No external dependencies, light-weight, supports all major browsers and highly customizable


  • Simple: is simple to use and has no external dependency at all
  • Light-weight: is just 5kb gzipped as compared to other libraries which are +12kb gzipped
  • 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
  • TypeScript: Written in TypeScript
  • Consistent behavior: usable across all browsers
  • MIT Licensed: free for personal and commercial use

Documentation

For demos and documentation, visit driverjs.com

Please note that above documentation is for version 1.x which is the complete rewrite of driver.js.
For 0.x documentation, please visit this page


So, yet another tour library?

No, it's more than a tour library. Tours are just one of the many use-cases. Driver.js can be used wherever you need some sort of overlay for the page; some common usecases could be: highlighting a page component when user is interacting with some component to keep them focused, providing contextual help e.g. popover with dimmed background when user is filling a form, using it as a focus shifter to bring user's attention to some component on page, using it to simulate those "Turn off the Lights" widgets that you might have seen on video players online, usage as a simple modal, and of-course product tours etc.

Driver.js is written in Vanilla TypeScript, has zero dependencies and is highly customizable. It has several options allowing you to change how it behaves and also provides you the hooks to manipulate the elements as they are highlighted, about to be highlighted, or deselected.

Also, comparing the size of Driver.js with other libraries, it's the most light-weight, it is just ~5kb gzipped while others are 12kb+.


Contributions

Feel free to submit pull requests, create issues or spread the word.

License

MIT © Kamran Ahmed

NPM DownloadsLast 30 Days