Last active
August 29, 2015 14:23
-
-
Save samuelbeek/b5ddbbced6068ae250ff to your computer and use it in GitHub Desktop.
Random Background Directive
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
// 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; | |
} |
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
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