Categories
CSS Web development

CSS Shake Animation

In this tutorial you’ll learn how to shake/wiggle image and text with CSS.

CSS Shake Animation
Do you like this image? Check more images in theĀ store.
To see live output go to: lenastanley.com

Let’s shake it!

Shake the Image and the text.

Step 1.

Add HTML

<body>
  <center>
    <section class="content">
      <h1>Shake it!</h1>
      <h2>Move your mouse over the image and the text.</h2>
        <br>
        <br>
          <img src="https://lenadesign.org/wp-content/uploads/2020/01/gs1.png?w=640" alt="greenjuice" class="shake">
      <h2 class="shake">Shake text too!</h2>
    </section>
  </center>
</body>

Step 2.

Add CSS

body{
  background-color:#58D68D;
}
.content {
  margin: 5% 0 0 0%;
}
.shake {
	display:inline-block
}
.shake {
	display:block;
	position:relative;
}
img{
display: block;
height: 480px;
width: 680px;
margin-left: auto;
margin-right: auto;
}
h2.shake,
.shake.inline {
	display:inline-block
    
}
h1,h2{
  color:#FFF;

Step 3.

Add CSS Animation

}
@-webkit-keyframes spaceboots {
	0% { -webkit-transform: translate(2px, 1px) rotate(0deg); }
	10% { -webkit-transform: translate(-1px, -2px) rotate(-1deg); }
	20% { -webkit-transform: translate(-3px, 0px) rotate(1deg); }
	30% { -webkit-transform: translate(0px, 2px) rotate(0deg); }
	40% { -webkit-transform: translate(1px, -1px) rotate(1deg); }
	50% { -webkit-transform: translate(-1px, 2px) rotate(-1deg); }
	60% { -webkit-transform: translate(-3px, 1px) rotate(0deg); }
	70% { -webkit-transform: translate(2px, 1px) rotate(-1deg); }
	80% { -webkit-transform: translate(-1px, -1px) rotate(1deg); }
	90% { -webkit-transform: translate(2px, 2px) rotate(0deg); }
	100% { -webkit-transform: translate(1px, -2px) rotate(-1deg); }
}
.shake:hover,
.shake:focus {
	-webkit-animation-name: spaceboots;
	-webkit-animation-duration: 0.8s;
	-webkit-transform-origin:50% 50%;
	-webkit-animation-iteration-count: infinite;
	-webkit-animation-timing-function: linear;
}

To see live output go to: lenastanley.com

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *