I want to add an animation to my button without having to hover on it, exactly like the example here Add CSS shaking animation to a button without hover
but with a differet animation, preferably pulse animation but my coding knowladge is not that much
can anybody help me with that please thank you in advance.
Here's the code you can try to add a pulse animation:
.pulse-button {
/* Button default styles, customize them to match your button */
display: inline-block;
padding: 10px 20px;
color: #fff;
background-color: #3498db;
border: none;
border-radius: 4px;
cursor: pointer;
/* Apply the pulse animation */
animation: pulse 1s infinite;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
To break it down for you:
animation: pulse 1s infinite;
The animation property applies the pulse effect to the button. This property specifies:
Then the keyframe animation:
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
100% {
transform: scale(1);
}
}
This @keyframes rule defines the actual pulse animation. The pulse animation works as follows:
Any button with the class .pulse-button will continuously "pulse" by slightly increasing and then returning to its original size.
Here's a demo of the working code on JSFiddle
.pulseBtn {
background:#0b63bb;
color:#fff;
border:1px solid #0b63bb;
padding:1rem 2rem;
border-radius:2rem;
font-size:1rem;
box-shadow: 0 0 0 0 rgba(88, 120, 243, 0.4);
-moz-animation: pulse 2s infinite;
-webkit-animation: pulse 2s infinite;
animation: pulse 2s infinite;
}
@keyframes pulse {
0% {
box-shadow: 0 0 0 0 rgba(88, 120, 243, 1);
}
70% {
box-shadow: 0 0 0 10px rgba(88, 120, 243, 0);
}
100% {
box-shadow: 0 0 0 50px rgba(88, 120, 243, 0);
}
}
<button class="pulseBtn">Pulse Animation</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With