Trigger A Function When The User Goes Idle – idle-tracker

Category: Javascript | March 13, 2019
Author: roderickhsiao
Views Total: 151
Official Page: Go to website
Last Update: March 13, 2019
License: MIT

Preview:

Trigger A Function When The User Goes Idle – idle-tracker

Description:

A small idle tracker library that tracks user interactions on the webpage and fires a callback function if the user goes idle.

Default events the library listens for:

  • change
  • keydown
  • mousedown
  • mousemove
  • mouseup
  • orientationchange
  • resize
  • scroll
  • touchend
  • touchmove
  • touchstart
  • visibilitychange

How to use it:

Install the library with package managers.

# Yarn
$ yarn add idle-tracker

# NPM
$ npm install idle-tracker --save

Import the idle-tracker.

import IdleTracker from 'idle-tracker';

Or load the umd version of the idle-tracker in the document.

<script src="dist/index.js"></script>
<script src="dist/active-events.js"></script>

Create a new Idle Tracker and specify the timeout, callback function, and active events.

var idelTracker = new Tracker({
    timeout: 3000,
    onIdleCallback: idleFunction,
    throttle: 500
    events: activeEvents.default
});

Start the idle tracker and done.

idelTracker.start();

Changelog:

03/13/2019

  • Fix function not removed on end

You Might Be Interested In:


Leave a Reply