-
-
Save rebelholic/d7fd0646e43b3bca306124838c73e070 to your computer and use it in GitHub Desktop.
Random Background Color Directive for Angularjs
This file contains hidden or 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
// just add random-backgroundcolor to the element you want to give a random background color | |
app.directive("randomBackgroundcolor", function () { | |
return { | |
restrict: 'EA', | |
replace: false, | |
link: function (scope, element, attr) { | |
//generate random color | |
var color = '#' + (Math.random() * 0xFFFFFF << 0).toString(16); | |
//Add random background class to selected element | |
element.css('background-color', color); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment