Skip to content

Instantly share code, notes, and snippets.

@jonathanstark
Last active December 25, 2015 02:19
Show Gist options
  • Save jonathanstark/6902015 to your computer and use it in GitHub Desktop.
Save jonathanstark/6902015 to your computer and use it in GitHub Desktop.
(function (d, w, activeClass) {
if (('ontouchstart' in w) || w.DocumentTouch && d instanceof DocumentTouch) {
var activeElement = null,
clearActive = function() {
if (activeElement) {
activeElement.classList.remove(activeClass);
activeElement = false;
}
},
setActive = function(e) {
clearActive();
if (e.target.tagName == 'A') {
activeElement = e.target;
activeElement.classList.add(activeClass);
}
};
d.documentElement.classList.add('touch');
d.documentElement.classList.remove('no-touch');
d.body.addEventListener('touchstart', setActive, false);
d.body.addEventListener('touchmove', clearActive, false);
}
})(document, window, 'active');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment