Created
April 12, 2011 18:59
-
-
Save austintaylor/916145 to your computer and use it in GitHub Desktop.
Used this to track down a crazy JS bug one time. Still makes me smile.
This file contains 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
var eventColors = { | |
mouseover: 'red', | |
mouseout: 'blue', | |
click: 'yellow' | |
} | |
var highlight = function(event) { | |
Event.stop(event); | |
element = Event.element(event); | |
Element.setStyle(element, {backgroundColor: eventColors[event.type]}); | |
setTimeout(Element.setStyle.bind(null, element, {backgroundColor: ''}), 200); | |
} | |
Event.observe(window, 'load', function() { | |
Event.observe(document.body, 'mouseover', highlight.bindAsEventListener()); | |
Event.observe(document.body, 'mouseout', highlight.bindAsEventListener()); | |
Event.observe(document.body, 'click', highlight.bindAsEventListener()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment