1.0.1 • Published 5 years ago

egress-intent v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

EgressIntent

OuiBounce originally created by Carl Sednaoui from MailCharts. Ported to TypeScript and adapted into EgressIntent by Sean Bennett.

EgressIntent offers a simple interface to execute code as the user's cursor exits a given area, with the added functionality of limiting the number of times this can occur over a given period of time by setting a cookie.

An adaptation of the OuiBounce library from Carl Sednaoui and other contributors, it has diverged from the original library:

  • EgressIntent eschews the original library's style attribute modification of a given "modal" element on exit trigger, instead leaving the exact code to execute up to the developer.

Installation

Simply run npm install egress-intent.

Usage

Basic Usage:

EgressIntent is intended for use with a module bundler. For a project with ES6 modules enabled, simply:

import EgressIntent from 'egress-intent';

const trigger = new EgressIntent({
    callback: () => { console.log('Fired'); }
});

If using another module loader:

const EgressIntent = require('egress-intent').default;

Methods

The trigger can be manually fired:

trigger.fire();

Or disabled:

trigger.disable();

Options

OptionTypeDefaultDescription
aggressivebooleanfalseIgnores whether a cookie has been set and always fires on exit.
timernumber1000The number of milliseconds after which to attach handlers. Reduces false positives.
delaynumber0The number of milliseconds after which the user has exited the callback should trigger. Setting this allows the user to briefly exit and then return without triggering.
cookieExpirenumber1The number of days after which the cookie should expire and trigger the code again for the user.
cookieDomainstring''If you need a cookie to work also in your subdomain (like blog.example.com and example.com), then set a cookieDomain such as .example.com (notice the dot in front).
cookieNamestring'triggeredEI'If desired, override the default cookie name.
sitewidebooleanfalseIf true, the cookie will apply to every page of the site rather than only that which the user triggered the code to be fired.
targetHTMLElementdocument.documentElementThe element that defines the boundaries of the exit.
sensitivitynumber20How far the mouse must be from the edge.
directionsstring or string[]['top', 'right', 'bottom', 'left']The exit directions that will trigger the callback.

When manually calling the disable() method on the class, custom cookie options (cookieExpire, cookieDomain, cookieName, and sitewide) can be specified that override those set when the class was instantiated:

trigger.disable({
    cookieExpire: 10
});
1.0.1

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago