Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Css - animating background image - zoom effect with loop

Tags:

html

css

I'm looking for clean way to archive effect using css3 animations :

I have div, which has css style:

background-image:url('image.png');
background-size:cover;
/* Just to note this page has 100% width and 100% height */
width:100%;
height:100;

This two rules, makes image full screen. Now, im looking for a way, to create effect of zoom, for let's say 5 seconds. So user on page load see full page background, which is getting smaller, but all the time is 100 % width and height.

I found some examples, but most of them use :hover effect, and i want to have animation on page load.

Thanks for advice.

like image 854
Marek Brzeziński Avatar asked Nov 26 '15 15:11

Marek Brzeziński


People also ask

Can you animate a background image in CSS?

You can use CSS to create trendy animations and visual effects. You don't need to know JavaScript or even HTML and create different kinds of animations and environments on your website. Our team at Slider Revolution has researched CSS animated background examples that can help you create fun websites.

How do you make a background image hover?

This task can be simply done by using the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover. Example: HTML.


1 Answers

Start the image background-size as greater than 100% and then use a keyframe animation it 'scale' it down to 100% as the end value.

For a loop, use animation-direction: alternate;

body {
  height: 100vh;
  background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3999/Tilt-Shift_-_Cityscene.jpg);
  background-size: 110% 110%;
  background-position: center center;
  animation: shrink 5s infinite alternate;
}
@keyframes shrink {
  0% {
    background-size: 110% 110%;
  }
  100% {
    background-size: 100% 100%;
  }
}
like image 125
Paulie_D Avatar answered Sep 28 '22 10:09

Paulie_D