Lior Bar
Lior Bar

Reputation: 223

How to zoom in and out an image every second?

I'm looking for solution to my problem. I want to zoom in and out without stoping every second in a div with backgroung-image.

Something like this fruit in the game:

https://www.google.co.il/search?source=hp&ei=ghU7XfaEBai4gwfA6rrIDA&q=snake&oq=snaj&gs_l=psy-ab.1.0.35i305i39j0i10l9.776.1740..2868...0.0..0.192.754.0j5......0....1..gws-wiz.....0..35i39j0i131j0j0i67.KPZVLy3h8CU

I find the solution below but I use react so I need css/js solution and not jQuery one.

Zoom an image every one second jQuery

Upvotes: 2

Views: 933

Answers (1)

Lior Bar
Lior Bar

Reputation: 223

The solution is to use CSS "breathing" animation. An example how it works:

#breathing-button {
    width: 270px;
    padding: 20px;
    margin: 50px auto;
    border: 1px solid #d1d1d1;
    -webkit-animation: breathing 7s ease-out infinite normal;
    animation: breathing 7s ease-out infinite normal;
    font-size: 24px;
    background: #5885cb;
    color: #fff;
    -webkit-font-smoothing: antialiased;
    border-radius: 3px;
    text-align: center;    
    }


@-webkit-keyframes breathing {
  0% {
    -webkit-transform: scale(0.9);
    transform: scale(0.9);
  }

  25% {
    -webkit-transform: scale(1);
    transform: scale(1);
  }

  60% {
    -webkit-transform: scale(0.9);
    transform: scale(0.9);
  }

  100% {
    -webkit-transform: scale(0.9);
    transform: scale(0.9);
  }
}

@keyframes breathing {
  0% {
    -webkit-transform: scale(0.9);
    -ms-transform: scale(0.9);
    transform: scale(0.9);
  }

  25% {
    -webkit-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }

  60% {
    -webkit-transform: scale(0.9);
    -ms-transform: scale(0.9);
    transform: scale(0.9);
  }

  100% {
    -webkit-transform: scale(0.9);
    -ms-transform: scale(0.9);
    transform: scale(0.9);
  }
}
<div id="breathing-button">Breathing Button</div>

Upvotes: 1

Related Questions