Site logo

Archived topic

Scale background image on page load using block effects

7 replies · Started by Brenden on May 19, 2022

Viewing posts 1–8 of 8

I am trying to scale a background image after the page loads using block effects. Currently I can only get the scale effect to work on hover or if I change the 'state' from 'Hover' to 'Normal' the background image is already scaled and there is no animation to the scaled state.

I want to create an effect similar to the page hero on this page - https://bythehand.org/about-us/.

Hi Brenden,

You can try add the transition to the effect, set a long transition time, like 20s.

Hi there,

GBs effects won't trigger on load.
You will need some Javascript.

1. Keep the Effects you have so far.
2. Select the Container that has the Background image and in Advanced > Additional CSS Class(es) add: animated-hero
3. Use a Hook Element to add this script to the wp_footer:

<script>
var pagehero = document.querySelector('.animated-hero');
function hero_animation(){
	setTimeout(function() {
    pagehero.classList.add('loaded');
  }, 500 );
}

document.onload = hero_animation();
</script>

4. Add this CSS:

.animated-hero.loaded:before{
    transform: scale(1) perspective(1000px);
}

Note you can:

a. Adjust the 500 value in the #3 script - that adds a 500 ms delay before the class is added.
b. Adjust the transition time on your GB effect

That did the trick! Thank you!

Glad to be of help

This archived topic is closed to new replies.