I'm setting the background image of a page using :
body {
background: url(http://momentumbooks.com.au/wp-content/uploads/2013/06/space.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
text-align: center;
}
I would like to read a property from a scoped variable in my controller that looks like this:
$scope.image="http://momentumbooks.com.au/wp-content/uploads/2013/06/space.jpg"
How can I set this css body attribute from within my .html page ? In jQuery I could .css(). Can I do something similar using angulalJs? http://docs.angularjs.org/guide/dev_guide.templates.css-styling doesn't seem to detail this ?
I'm trying this fiddle but does not work :
http://jsfiddle.net/U3pVM/3015/
fiddle code :
<body ng-style="getBodyStyle()">
</body>
$scope.getBodyStyle = function () {
return {background: "url(http://momentumbooks.com.au/wp-content/uploads/2013/06/space.jpg) no-repeat center center fixed;"};
};
document.body.style.background = url(variable);
ordocument.body.style.backgroundImage = url(variable);
– brouxhaha Feb 14 at 23:47url
defined that returns the proper syntax, you might want to add appropriate quotes … – CBroe Feb 14 at 23:50= 'url(' + variable + ')';
– brouxhaha Feb 15 at 0:56