I intend to move to the left for 1 second and to the right for 1 second, so that it looks like it is shaking, each movement about 3 times
this is my code but it doesn't do both movements it only does the first one
#formulario:hover{
/*position: absolute;*/
-moz-transition-property: background-color, color, left;
-moz-transition-duration: 1s;
-webkit-transition-property: background-color, color, left;
-webkit-transition-duration: 1s;
-o-transition-property: background-color, color, left;
-o-transition-duration: 1s;
background-color: #CEF6CE;
left: -15px;
right: -15px;
position: relative;
}
I think the effect you're looking for is to shake the element for several seconds. You can do this with
keyframes
.Source: CSS-Tricks .
If not, you can use the classes provided on this page: https://elrumordelaluz.github.io/csshake/ through which you have different effects to shake your elements.
You would simply have to add the link to their css and use the classes they provide you in the elements you want to shake.
Usage example:
Possible solution in JavaScript would be to make a recursive timeOut that will carry out the pertinent modifications.
Taking advantage of the fact that the CSS transform property is easily scriptable, something similar to this can be done.
(If you don't want to use transform, you can use the same system by adding a different parse)
The script and the speed could also be passed by value and make the function more generic... or even include the speed in the script to indicate different speeds between frames...
As the "shake" effect is fast, I have not included a transition, but if you want smoothness just add
elemento.style.transition=velocidad/1000+"s";
after declaring the variablevelocidad
, but remember to remove it afterwards.