I would like to shake this text every 5 seconds, so I tried to implement an animation in CSS and set an interval via jQuery, but it seems something is wrong...and ideas what's missing? Here's a fiddle: https://jsfiddle.net/s909gu2s/1/
.shk {
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
-webkit-animation-name: shake;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-webkit-animation-delay: 0s;
}
@keyframes shakeMe {
10%, 90% {
transform: translate3d(-5px, 0, 0);
}
20%, 80% {
transform: translate3d(5px, 0, 0);
}
30%, 50%, 70% {
transform: translate3d(-5px, 0, 0);
}
40%, 60% {
transform: translate3d(5px, 0, 0);
}
}
$(document).ready(function() {
setInterval(function() {
$(".shk").css("animation", "shakeMe");
}, 500);
});
<div class="shk">Shake me</div>
Set the speed To run your animation effect at a faster or slower pace, change the Duration setting. On the slide, click the text or object that contains the animation effect that you want to set the speed for. On the Animations tab, in the Duration box, enter the number of seconds that you want the effect to run.
Answer: Ctrl F6 is used to repeat the animation. Explanation: Animation is used to transform static objects into motion.
You can use integer values to define a specific amount of times the animation will play. animation-iteration-count: infinite; By using the keyword infinite , the animation will play indefinitely.
You can also specify the number of animation iterations using the animation shorthand CSS property to use fewer lines of code. For example, in the following code: animation: example 3s 2s 5 ease; … the value 5 sets the number of animation iterations.
You can do it with pure CSS, no JS/jQuery needed. In order to accomplish this, I set the animation-duration
to 5 seconds, then multiplied all percentage values by 0.2 (because 1 second out of 5 seconds => 20%). Then translate back to 0px after the highest percentage value. And voilà, shaking every 5 seconds:
.shk {
transform: translate3d(0, 0, 0);
backface-visibility: hidden;
animation-name: shakeMe;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}
@keyframes shakeMe {
2%, 18% {
transform: translate3d(-5px, 0, 0);
}
4%, 16% {
transform: translate3d(5px, 0, 0);
}
6%, 10%, 14% {
transform: translate3d(-5px, 0, 0);
}
8%, 12% {
transform: translate3d(5px, 0, 0);
}
18.1% {
transform: translate3d(0px, 0, 0);
}
}
<div class="shk">Shake me</div>
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