Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a pulse effect on an image for a couple seconds when the page loads?

Tags:

html

jquery

css

I am trying to create a pulse effect on an image but it is not working so far. I have tried to a span element and it works like that:

HTML:

<span class="pulse"></span>

CSS:

.pulse {
  margin:100px;
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #cca92c;
  cursor: pointer;
  box-shadow: 0 0 0 rgba(204,169,44, 0.4);
  animation: pulse 2s infinite;
}
.pulse:hover {
  animation: none;
}

@-webkit-keyframes pulse {
  0% {
    -webkit-box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
  }
  70% {
      -webkit-box-shadow: 0 0 0 10px rgba(204,169,44, 0);
  }
  100% {
      -webkit-box-shadow: 0 0 0 0 rgba(204,169,44, 0);
  }
}
@keyframes pulse {
  0% {
    -moz-box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
    box-shadow: 0 0 0 0 rgba(204,169,44, 0.4);
  }
  70% {
      -moz-box-shadow: 0 0 0 10px rgba(204,169,44, 0);
      box-shadow: 0 0 0 10px rgba(204,169,44, 0);
  }
  100% {
      -moz-box-shadow: 0 0 0 0 rgba(204,169,44, 0);
      box-shadow: 0 0 0 0 rgba(204,169,44, 0);
  }
}

I want to the same with this image:

<a href="javascript:void(0)" class="item">
  <img src="https://image.ibb.co/cNjXna/guided_inv_icon.png" alt="">
</a>

When the page loads, the image should have a pulse effect or only get the image a bit bigger for 2 seconds in order to indicate interactivity and then the image should keep his original shape.

Any suggestions?

I have created this pen: https://codepen.io/maketroli/pen/ZyOJYM

EDIT

I need to create that same effect in the image below the yellow circle. The yellow circle made from the span is doing what I want to achieve with the image below.

like image 820
Reacting Avatar asked Feb 05 '23 06:02

Reacting


1 Answers

You can apply the same animation to the image, similar to how you applied the animation to the span element.

.item img{
animation: pulse 2s infinite;
}

Check out this pen

EDIT

For showing a bigger image for 2 seconds and then reducing it to normal size, I have added the magnified animation.

@keyframes magnified{
0%{
transform: scale(1.2,1.2);
}
70%{
transform: scale(1.2,1.2);
}
100%{
transform: scale(1,1);
}
}

And you can add multiple animations to the element:

.item img{
animation: pulse 2s infinite, magnified 2s 1;
}

I have updated the pen to show these effects.

like image 174
Haris Avatar answered Mar 02 '23 13:03

Haris