Hi,
I need to toggle a background color on and off depending on the form I’m opening, to blend it with a picture in the background.
I want to add it in the rgba format , because I need transparency.
This is what I have in the HTML. (the two commented lines inside the style is what I need to turn on and off)
<link href="https://fonts.googleapis.com/css?family='Athena Unicode':300,400,500" rel="stylesheet" rel="preload" as="font" crossorigin="anonymous">
<style>
body {
/* background-color: rgba(255, 253, 250,.9); */
background-image: url('https://images.pexels.com/photos/6753885/pexels-photo-6753885.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2');
/* background-blend-mode: screen; */
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
background-attachment: fixed;
}
<div class="structure">
<div class="app-bar" anvil-drop-container=".anvil-container" anvil-drop-redirect=".placeholder">
<a class="sidebar-toggle" anvil-if-slot-empty="top-left-btn" anvil-hide-if-slot-empty="left-nav" anvil-drop-slot="top-left-btn" href="javascript:void(0)"><i class="fa fa-bars"></i></a>
<a class="sidebar-toggle anvil-designer-only" anvil-if-slot-empty="top-left-btn" anvil-if-slot-empty="left-nav" anvil-drop-slot="top-left-btn"><i class="fa fa-blank"></i></a>
<div class="top-left-btn" anvil-slot="top-left-btn"></div>
<div class="title" anvil-slot="title">
.
.
.
I’ve tried using javascript:
This in the native libraries:
function setColor(color) {
document.body.style.backgroundColor = color;
}
And this in the python code:
def form_show(self, **event_args):
self.call_js('setColor', 'rgba(255, 253, 250,.9)')
But It’s not changing to the color.
I’ve also tried with the following in the form_show event
body = dom_node.querySelector(".anvil-root-container")
body.style.backgroundColor= rgba(255, 253, 250,.3)
The thing is I think I’m not targetting the right element, and I cannot find out which one is. (I would say it is the body, because if I uncomment the line in the style it works, but I’m not sure)
I know that this could probably be done with javascript and also from python using the
anvil.js.window
anvil.js.get_dom_node(component)
And I think that probably this would be the more anvilistic way to do it.
I attach a reduced copy of the app to help see more clearly what could be the problem.
The app loads a sort for landing page and when you press the button Go, it opens another form in which I would like to activate the background color and blend-mode to soften the background image.
Thank you!!