Last active
September 1, 2015 11:45
-
-
Save timotgl/43e0bd0b68874925024a to your computer and use it in GitHub Desktop.
Log all pointer events (mouse and touch gestures)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var span, eventTypes = [ | |
'click', 'mousedown', 'mouseup', 'mouseover', 'mousemove', 'mouseout', | |
'touchstart', 'touchend', 'touchmove', 'touchcancel', 'touchleave' | |
]; | |
var header = document.querySelector('#header .header-wrap'); | |
// Log a single gesture to the console and show it at the top of the page. | |
function logEvent (event) { | |
console.log(event.type); | |
span = document.createElement('span'); | |
span.style.color = 'white'; | |
span.appendChild(document.createTextNode(event.type + ' -> ')); | |
header.insertBefore(span, header.firstChild); | |
} | |
// Attach event listeners for all gestures. | |
for (var i = 0; i < eventTypes.length; i++) { | |
document.addEventListener(eventTypes[i], logEvent); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment