Coder Social home page Coder Social logo

perimeter.js's Introduction

Perimeter.js

Creates an invisible perimeter around a target element and monitors mouse breaches.

More info, documentation and examples @ http://github.e-sites.nl/perimeter.js/

##Use cases

  • Showing some sort of tooltip / popover when hovering near a certain element, like a hint or a tip
  • Lazy load a script when the perimeter of the target element is breached (AFAIK Google does this when a user moves it's mouse towards the red 'compose' button).
  • Fetch data via AJAX and do something with it when a users navigates towards a certain element

##Specs

  • Lightweight; (~0.6kb minified / gzipped)
  • No dependencies; just plug it in and you're good to go
  • Built-in debugger to actually see where the perimeter is located (boundary.js)
  • Fully documented
  • Unit-tests available (when 0.2.0 lands)

##Getting started First and foremost, download the script and include it as follows:

<script src="perimeter.min.js"></script>

Second, just call the Perimeter constructor function and pass the corresponding options.

new Perimeter({
    target: 'square',
    outline: 20,
    onBreach: function () {
        // Breach!
    }
});

In case you're working with perimeter.debug.js you'll need to add a bit of CSS to actually see the boundary:

.boundary {
    position:absolute;
    border:1px dotted;
    background:#E4FECB;
    background:rgba(127,255,0,0.2);
    margin:0;
    padding:0;
    z-index:-1;
}

###Options

Property Type Description
target {String} The ID of the target element
monitor {HTMLElement} Element where the mousemove event will be bound to and therefore acts as monitor for breaches.
outline {Number|Array} Outline around the target element. This can either be an array with top/right/bottom/left dimensions or just one number which acts as shorthand for all directions.
debug {Boolean} When debugging in a local environment you can pass the debug option. This will create a division that will be positioned absolutely to the body and basically shows where the perimeter is located. By default, the debug functionality is excluded from perimeter.js. So, please make sure that you include perimeter.debug.js.
onBreach {Function} Callback function that will be invoked when the monitor detects a breach.
onLeave {Function} Callback function that will be invoked when the mouse cursor leaves the perimeter.

##Browser support Tested in the latest (stable) versions of Google Chrome, Mozilla Firefox, Opera and Safari. As for Internet Explorer; I have tested in IE8+ but it should work in IE7 as well (though, it might be quirky).

##Road map

When I have some spare time I will try to accomplish the following:

  • Performance measurements
  • More documentation / examples
  • Unit testing

##License Copyright (C) 2013 e-sites, http://e-sites.nl/ Licensed under the MIT license.

perimeter.js's People

Contributors

boye avatar

Watchers

James Cloos avatar Huy Nguyen Quang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.