How can I prevent the original background from loading for 2 seconds before my chosen background image on my Webflow website's "Hero Overlay" div block?

Published on
September 22, 2023

To prevent the original background from loading for 2 seconds before your chosen background image on your Webflow website's "Hero Overlay" div block, you can use CSS and a little bit of JavaScript. Here's a step-by-step guide:

  1. First, make sure you have added the chosen background image to your Webflow project. You can do this by going to the Webflow Designer and selecting the "Hero Overlay" div block.
  2. In the Style panel on the right, select the "Background" tab and choose the desired background image from the options.
  3. Now, let's add custom CSS to hide the original background until the chosen image loads.
  • Open the Webflow Designer and select the "Hero Overlay" div block.
  • In the Style panel, scroll down to the Custom Code section.
  • Under the "Head Code" tab, paste the following CSS code:
<style>  .hero-overlay {    background-color: transparent !important;  }</style>
  1. Once you've added the CSS code, we need to add a small JavaScript snippet to delay the background image load.
  • Go to the "Before " tab in the Custom Code section.
  • Paste the following JavaScript code:
<script>  setTimeout(function() {    document.querySelector('.hero-overlay').style.backgroundColor = "";  }, 2000);</script>

This script sets a 2-second delay (specified in milliseconds) before setting the background color to transparent. Adjust the duration as needed.

  1. Finally, make sure to publish your website to see the changes take effect.

By following these steps, you can prevent the original background from loading for 2 seconds before your chosen background image on your Webflow website's "Hero Overlay" div block. This will provide a smoother and more seamless transition for your users.

Additional Resources:

Q1: How can I hide the original background image in Webflow?
Q2: Is it possible to delay the loading of a background image in Webflow?
Q3: How can I customize the appearance of a Div block in Webflow?