Created
August 11, 2014 15:53
-
-
Save abovedave/5aa6409633aca91cfc7a to your computer and use it in GitHub Desktop.
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
// ------------------------ | |
// Syntax 'input:class:target' for toggling classes | |
// E.g., data-class="body:show-nav:header nav" | |
$('[data-class]').each(function(){ | |
var self = $(this), | |
input = self.data('class').split(':'), | |
root = $(input[0]), | |
theclass = input[1], | |
target = $(input[2]), | |
transtionend = 'webkitTransitionEnd otransitionend mstransitionEnd transitionend'; | |
if (input && input.length > 1){ | |
self.on('click', function(){ | |
if (root.hasClass(theclass)) { | |
root.removeClass(theclass+'-animate'); | |
target.one(transtionend, function(){ | |
root.removeClass(theclass); | |
}); | |
} else { | |
target.unbind(transtionend); | |
root.addClass(theclass); | |
// Cheap and nasty :S | |
setTimeout(function () { | |
root.addClass(theclass+'-animate'); | |
}, 20); | |
} | |
return false; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment