Mobile and Desktop Event Normalization with pointer.js

By  on  

The mobile revolution brought in a variety of new challenges, one being interaction and event handling.  We have a set of new touch events and the traditional desktop events, and click events work on both devices, but mousemove and touchmove aren't always in sync, and there are a number of other nuances you run into with different devices.  That's why Mozilla's uber-talented Web Developer Potch created pointer.js, a utility to help developers more easily manage events across devices.

pointer.js Documentation

The pointer.js documentation explains the project as well and simply as it should, so I wont reinvent the wheel.  Straight from the docs:

Types of Events

The following events are generated:

  • pointerdown: based on mousedown/touchstart
  • pointerup: based on mouseup/touchend
  • pointermove: based on mousemove/touchmove
  • pointerleave: based on mouseout/touchleave
  • pointerclick: a 'fast click' event based on a sequence of the above events. Additional heuristics are applied to determine whether or not to generate a pointerclick.

Event Objects

pointer events have the following custom properties:

  • maskedEvent: the event that triggered the pointer event.
  • touch: boolean- is maskedEvent a touch event?
  • mouse: boolean- is maskedEvent a mouse event?
  • x: page-normalized x coordinate of the event.
  • y: page-normalized y coordinate of the event.

Simple APIs are the best APIs, and Potch nailed this one.

pointer.js Usage

Here are a few example usages of pointer.js:

var element = document.getElementById("myElement");

element.addEventListener("pointerdown", function(detailedEvent) {
	// Do something

element.addEventListener("pointerleave", function(detailedEvent) {
	// Do something

element.addEventListener("pointerclick", function(detailedEvent) {
	// Do something
	if(detailedEvent.mouse) {
		// desktop
	else {
		// mobile

Potch wrote the JS such that you are adding custom event listeners in a traditional way via addEventListener.  I also love that Event object is true, not a new object that provides the original event as one property.  The additional information added to the object is useful in identifying the platform and which event was actually fired.

Event normalization was one of the original reasons for the first event frameworks...and they didn't even have to deal with mobile devices!  Potch has done well with this event normalization utility and I can't wait to use it on my next redesign!

Recent Features

  • By
    Introducing MooTools Templated

    One major problem with creating UI components with the MooTools JavaScript framework is that there isn't a great way of allowing customization of template and ease of node creation. As of today, there are two ways of creating: new Element Madness The first way to create UI-driven...

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

Incredible Demos

  • By
    Drag and Drop MooTools File Uploads

    Honesty hour confession:  file uploading within the web browser sucks.  It just does.  Like the ugly SELECT element, the file input is almost unstylable and looks different on different platforms.  Add to those criticism the fact that we're all used to drag and drop operations...

  • By
    Highlighter: A MooTools Search & Highlight Plugin

    Searching within the page is a major browser functionality, but what if we could code a search box in JavaScript that would do the same thing? I set out to do that using MooTools and ended up with a pretty decent solution. The MooTools JavaScript Class The...


  1. Peter Galiba

    Sad, but the pointer.js do not support Pointer events developed by Microsoft for Windows 8 and used in IE10+. Without that supported, I would not call it pointer.js as it does not support pointers, not even multiple pointers. In MS terms a pointer could be mouse, touch or pen. For more details about pointer events see

  2. @Peter +1. Without windows 8 support i can’t use it at all. Sadly.

  3. Fançois

    What are IE10 and IE8 ?
    Pretty sure IE8 must die.
    With all the problems generated by Micrisoft, you should develop for the web, and not for Microsoft.

    Built web for next users, not just for you and your customers.
    You’ll be happy to make a better world/web ;)

    • François



  4. yeah… do you say this to your clients or your boss as well? “Sorry, i develop only for the Web, not for Microsoft” – sorry but this is just stupid.
    While i agree Microsoft is making our lives not easier, it’s the largest platform. Not supporting it is not an option – at all.

  5. Shameless self-promotion alert… if you’re looking for a Pointer Events polyfill that adheres more closely to the specification, I’ve written one called Points.js:

    It’s not perfect, but the specification as it stands is un-polyfillable (the Points.js readme goes into why, and what the limitations are).

    The W3C’s Pointer Events working group is also working towards a more spec-compliant ‘official’ polyfill. Also, the Polymer Project’s polyfill is well worth a look

  6. The article should contain information about the Pointer Events standard ( and how pointer.js relates to that standard. From what see from the README on GitHub, pointer.js is in the process of being rewritten to support that standard. This information should be mentioned in the article. Leaving it out risks causing confusion.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!