Skip to content

Instantly share code, notes, and snippets.

@boneskull
Created July 18, 2012 18:56
Show Gist options
  • Save boneskull/3138069 to your computer and use it in GitHub Desktop.
Save boneskull/3138069 to your computer and use it in GitHub Desktop.
angular directive to fadeIn/hide
/**
* Fades an element in when the model changes. Restricted to attributes.
*
* Usage:
*
* <div di-fade-in="foo"/>
*/
di.directive('diFadeIn', function () {
return {
restrict: 'A',
link: function (scope, element, attribs) {
scope.$watch(attribs.diFadeIn, function (value) {
if (value) {
element.fadeIn();
} else {
element.hide(); // hide immediately; don't fade out
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment