What I’m trying to do:
I’m trying to add a small loading GIF in place of a larger image while it’s loading in my Anvil app. The challenge is that when I use the GIF as a placeholder for the image, it expands to fill the entire space designated for the larger image. I want the GIF to remain small, centered, and not scaled up, to indicate a loading state without overwhelming the UI.
What I’ve tried and what’s not working:
I attempted to control the size of the GIF using CSS, applying styles directly to the Image component to reduce its size and center it. However, the GIF still expands to fill the entire space of the larger image it’s meant to be a placeholder for. I’ve also tried setting the dimensions of the Image component programmatically when setting the GIF as the source, but the outcome remains the same.
Here are some of the CSS styles and Python code I’ve experimented with:
# Setting the source and attempting to control size via inline styles
self.image_1.source = "path/to/loading.gif"
self.image_1.attributes['style'] = "width: 50px; height: auto; margin: auto;"
# Applying a CSS class (defined in the Assets section) to the Image component
self.image_1.set_css_class('small-loading-gif')
And the corresponding CSS:
.small-loading-gif {
width: 50px;
height: auto;
margin: auto;
}
Despite these attempts, the GIF still fills the entire space intended for the larger image, instead of remaining small and centered.