<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hamza Shahab</title>
    <description>The latest articles on DEV Community by Hamza Shahab (@hamzashahab1610).</description>
    <link>https://dev.to/hamzashahab1610</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F353156%2F0e09b4dd-7982-4037-966e-8ee34be1cf81.jpeg</url>
      <title>DEV Community: Hamza Shahab</title>
      <link>https://dev.to/hamzashahab1610</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hamzashahab1610"/>
    <language>en</language>
    <item>
      <title>Web Animations</title>
      <dc:creator>Hamza Shahab</dc:creator>
      <pubDate>Thu, 27 Aug 2020 08:39:26 +0000</pubDate>
      <link>https://dev.to/zenveus/web-animations-2n8a</link>
      <guid>https://dev.to/zenveus/web-animations-2n8a</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Animations play an important role in our day to day internet surfing. They make the online loading experience more entertaining for the users and develops interests among them.&lt;/p&gt;

&lt;p&gt;They are a powerful tool and are quite effective in making the online websites more interactive and engaging for the visitors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"Animation is the art of bringing life to images and graphical objects"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Animation?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;"A method in which pictures are manipulated to appear as moving images"&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this blog, I'll be focusing purely on CSS Animations. So let's get started!&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Animation
&lt;/h1&gt;

&lt;p&gt;Elements in web page can be shifted, rotated and transformed using CSS Animations. They can be moved across the page and interacted in all sorts of interesting ways.&lt;/p&gt;

&lt;p&gt;In order to develop a better understanding of CSS Animations, let's understand what keyframes are :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Keyframes
&lt;/h2&gt;

&lt;p&gt;In animation, &lt;strong&gt;&lt;em&gt;"A keyframe is a drawing that defines the starting and ending point of any smooth transition."&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see how we can implement a decent animation using keyframes, in an example below:&lt;/p&gt;

&lt;p&gt;For that we'll be needing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A static svg image&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy16kos6kwbiq7xbt5ydm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fy16kos6kwbiq7xbt5ydm.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;and... a bit of css xD&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The svg image is divided into smaller parts and each part is grouped and given a specific id which will be later used in CSS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqk0ztqrlnq09s0u9uiyy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqk0ztqrlnq09s0u9uiyy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now here's how we'll modify the code to make our asset move the way we want!&lt;/p&gt;

&lt;p&gt;We'll be creating separate keyframes for the transition and movement of different parts:&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Barbell
&lt;/h1&gt;

&lt;p&gt;The following code will aid in the vertical motion of the barbell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes barbell {
  from {
    transform: translateY(0%);
  }
  to {
    transform: translateY(42%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is then integrated to the corresponding part in svg by assigning the keyframe to the &lt;code&gt;animation&lt;/code&gt; attribute in &lt;code&gt;#Barbell&lt;/code&gt; selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#Barbell {
  width: 700px;
  height: auto;
  margin: 0;
  padding: 0;
  animation: barbell 1s ease-in-out 6 alternate;
  transform-origin: center;
  transform-box: fill-box;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  2. Arms
&lt;/h1&gt;

&lt;p&gt;This one's a bit tricky, so fasten your seat belts xD&lt;br&gt;
To illustrate the bending motion of the arms we further subdivided it to arm &amp;amp; forearm pair.&lt;/p&gt;
&lt;h2&gt;
  
  
  Forearm
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes foreArmLeft {
  from {
    transform: rotate(0deg) translateY(0%) translateX(0%) scaleY(1);
  }
  to {
    transform: rotate(8deg) translateY(35%) translateX(-63%) scaleY(0.65);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;translate(35%)&lt;/code&gt; adds a bit of vertical motion to the forearm to depict the lifting of barbell while the &lt;code&gt;rotate(8deg)&lt;/code&gt; illustrates the bending motion. This is then integrated to the forearm selector &lt;code&gt;#ForeArmLeft&lt;/code&gt; as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#ForeArmLeft {
  animation: foreArmLeft 1s ease-in-out 6 alternate;
  transform-origin: bottom;
  transform-box: fill-box;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Upper Arm
&lt;/h2&gt;

&lt;p&gt;The code below aids in moving the upper arm of the brain diagonally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes upperArmLeft{
  from {
    transform: translateY(0%) translateX(0%);
  }
  to {
    transform: translateY(270%) translateX(-60%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  3. Face
&lt;/h1&gt;

&lt;p&gt;The following 2 keyframes contribute to the transition of happy and sad moods of the brain.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes faceHappy{
  from{
    opacity: 1;
    transform: translateY(0%);
  }
  to{
    opacity: 0;
    transform: translateY(3%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes faceSad{
  from{
    opacity: 0;
    transform: translateY(0%);
  }
  to{
    opacity: 1;
    transform: translateY(3%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  4. Body
&lt;/h1&gt;

&lt;p&gt;The slight vertical motion of the body representing the brain's efforts to lift the barbell is created with the following piece of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@keyframes body {
  from {
    transform: translateY(0%);
  }
  to {
    transform: translateY(5%);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila! Our animation is now ready... Let's have a look!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/hamzashahab1610-the-decoder/embed/ExKmZzJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>react</category>
      <category>animations</category>
    </item>
  </channel>
</rss>
