Is there a way to dynamically change the background image of a website with the click of a button? I'm looking to update the background image attribute in the body tag using CSS and AngularJS.
CSS:
body {
background-color: #00471c;
background-image: url(http://www.transparenttextures.com/patterns/brushed-alum.png);
display: flex;
justify-content: center;
flex-direction: column;
}
HTML:
<input type="text" ng-model="newBackground" placeholder="Image URL for new background...">
<button ng-click="ng-style=body{background-image: url({{newBackground}})}" placeholder="Change background...">Change background</button>
While in practice, the button would actually trigger a function to retrieve the image URL based on the input, this setup demonstrates the concept.
Check out the JSFiddle example
Looking for a way to accomplish this task? Let's explore the possibilities.