Skip to content

Instantly share code, notes, and snippets.

@samuelbeek
Last active August 29, 2015 14:23
Show Gist options
  • Save samuelbeek/b5ddbbced6068ae250ff to your computer and use it in GitHub Desktop.
Save samuelbeek/b5ddbbced6068ae250ff to your computer and use it in GitHub Desktop.
Random Background Directive
// backgrounds:
.bgRed {
background-color: rgba(255,0,0,0.5)!important;
}
.bgYellow {
background-color: rgba(255,204,0,0.5)!important;
}
.bgGreen {
background-color: rgba(81,216,4,0.5)!important;
}
app.directive("randomBackground", function () {
return {
restrict: 'EA',
replace: false,
link: function (scope, elem, attr) {
var classes = ["bgRed", "bgGreen", "bgYellow"];
//Add random background class to selected element
elem.addClass(classes[Math.floor(Math.random() * (classes.length))]);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment