I'm facing a challenge with creating @keyframes animation CSS within an AngularJS directive function. The issue is that I need to use a variable from the scope to generate these keyframes, but I am unsure of how to retrieve it.
app.directive("myCSSDiv", function() {
var css = "@keyframes myAnimation {";
var nb_msg = ??? // In this line, I would like to access a variable like $scope.nb_msg but I am not sure how to do so
if(nb_msg == 2) {
css += "0%, 100% {left: 0px}";
css += "30%, 60% {left: -100px}";
} else if(nb_msg == 3) {
css += "0%, 100% {left: 0px}";
css += "15%, 50% {left: -100px}";
css += "60%, 85% {left: -200px}";
} else if(...) {
...
}
return {
restrict: "E",
template: css
}
});
If you have any suggestions or solutions, I would greatly appreciate it! Thanks!