<?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: Brian Montana</title>
    <description>The latest articles on DEV Community by Brian Montana (@brianmontanaweb).</description>
    <link>https://dev.to/brianmontanaweb</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%2F186475%2Fc8c1fcb0-3953-4b9c-bab9-218d311e9613.jpg</url>
      <title>DEV Community: Brian Montana</title>
      <link>https://dev.to/brianmontanaweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brianmontanaweb"/>
    <language>en</language>
    <item>
      <title>Canvas 101: Multiple Shapes and Resets</title>
      <dc:creator>Brian Montana</dc:creator>
      <pubDate>Tue, 20 Aug 2019 17:55:02 +0000</pubDate>
      <link>https://dev.to/brianmontanaweb/canvas-101-multiple-shapes-and-resets-37n</link>
      <guid>https://dev.to/brianmontanaweb/canvas-101-multiple-shapes-and-resets-37n</guid>
      <description>&lt;p&gt;This tutorial will build off the previous post I made; &lt;a href="https://dev.to/brianmontanaweb/canvas-101-rotating-shape-28la"&gt;Canvas 101: Rotating Shape&lt;/a&gt;, focusing on manipulating an array populated with objects created from a class.&lt;/p&gt;

&lt;p&gt;The last tutorial we used the &lt;code&gt;Square&lt;/code&gt; class to build an object that was updated over time with the &lt;code&gt;requestAnimationFrame&lt;/code&gt;method. Now we'll create multiple &lt;code&gt;Square&lt;/code&gt; instances, animate them across the canvas, and reset their position when they are completely off the screen.&lt;/p&gt;

&lt;p&gt;To begin let's fork this pen to start:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/brianmontanaweb/embed/jgWPmV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;First we will update the &lt;code&gt;Square&lt;/code&gt; class with &lt;code&gt;xVelocity&lt;/code&gt; in the deconstructed object of the constructor. We'll use this to move our square across the canvas, and rotate it as it moves. Setting a default value &lt;code&gt;0.1&lt;/code&gt;, or another similar smaller value, in the constructor we'll set the &lt;code&gt;xVelocity&lt;/code&gt; to a random value using its default value as the minimum and 1 as the maximum random value for &lt;code&gt;xVelocity&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;this.xVelocity = Math.random() * (1 - xVelocity) + xVelocity;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's check out the &lt;code&gt;movement&lt;/code&gt; function, right now we're incrementing the value by &lt;code&gt;0.1&lt;/code&gt;, but with the randomly generated &lt;code&gt;xVelocity&lt;/code&gt; we can increment it by the &lt;code&gt;xVelocity&lt;/code&gt; value over time. Every time you refresh you'll see a different speed. The square will continue to move off the canvas but we can include a check for the current position of the square and reset it to the left side of the canvas using this check &lt;code&gt;shape.xPosition &amp;gt; canvasWidth + shape.width&lt;/code&gt;. While doing this we'll want to set the new position to &lt;code&gt;-shape.width&lt;/code&gt;, placing it just outside the canvas, so it moves into the canvas instead of appearing on the edge. Here's the final update for the &lt;code&gt;movement&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function movement(shape) {
  if(shape.xPosition &amp;gt; canvasWidth + shape.width) {
    shape.xPosition = -shape.width;
  }
  shape.rotate += shape.xVelocity / 15;
  shape.xPosition += shape.xVelocity;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Awesome! We're seeing the &lt;code&gt;Square&lt;/code&gt; instance being animated and rendered across the canvas! Now we can setup an array and create multiple instances of &lt;code&gt;Square&lt;/code&gt;. Create an array at the top &lt;code&gt;const squares = [];&lt;/code&gt; and a value for the total count &lt;code&gt;let squareCount = 50;&lt;/code&gt; Now we have an array to push generated instances of &lt;code&gt;Square&lt;/code&gt;, while randomizing it's &lt;code&gt;xPosition&lt;/code&gt;, and &lt;code&gt;yPosition&lt;/code&gt;. The randomizing will use the same minimum and maximum threshold constraints in &lt;code&gt;xVelocity&lt;/code&gt;, we can think of it like this &lt;code&gt;Math.random() * (max - min) + min&lt;/code&gt;. To finalize it we'll use a &lt;code&gt;for&lt;/code&gt; loop to populate our &lt;code&gt;squares&lt;/code&gt; array with the limit of &lt;code&gt;squareCount&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i = 0; i &amp;lt; squareCount; i++) {
  squares.push(
    new Square({
      width: 40,
      height: 40,
      xPosition:
        Math.random() * (canvasWidth * 0.9 - canvasWidth * 0.1) +
        canvasWidth * 0.1,
      yPosition:
        Math.random() * (canvasHeight * 0.9 - canvasHeight * 0.1) +
        canvasHeight * 0.1
    })
  );
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since the &lt;code&gt;squares&lt;/code&gt; array is populated we'll need to update the &lt;code&gt;render&lt;/code&gt; function to determine the updated values for each &lt;code&gt;Square&lt;/code&gt; instance in the &lt;code&gt;squares&lt;/code&gt; array. Let's use the &lt;code&gt;forEach&lt;/code&gt; method provided by the &lt;code&gt;Array&lt;/code&gt; object to update each element's values with the &lt;code&gt;movement&lt;/code&gt; function, then drawing the results on the canvas. Each &lt;code&gt;Square&lt;/code&gt; instance will draw on top of the last one, so the last element in the array will be drawn on top of all the previous elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function render() {
  context.fillStyle = "lightsalmon";
  context.fillRect(0, 0, canvasWidth, canvasHeight);
  squares.forEach(square =&amp;gt; {
    movement(square);
    context.save();
    context.fillStyle = "salmon";
    context.translate(square.xPosition, square.yPosition);
    context.rotate(square.rotate);
    context.fillRect(
      -square.width / 2,
      -square.height / 2,
      square.width,
      square.height
    );
    context.restore();
  });
  window.requestAnimationFrame(render);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That should be it! Now all the squares will animate across the canvas and reset their position when they go off screen. See the results in the pen below :D&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>creativecoding</category>
      <category>tutorial</category>
      <category>codepen</category>
    </item>
    <item>
      <title>Canvas 101: Rotating Shape</title>
      <dc:creator>Brian Montana</dc:creator>
      <pubDate>Wed, 24 Jul 2019 18:55:54 +0000</pubDate>
      <link>https://dev.to/brianmontanaweb/canvas-101-rotating-shape-28la</link>
      <guid>https://dev.to/brianmontanaweb/canvas-101-rotating-shape-28la</guid>
      <description>&lt;p&gt;Never built anything in canvas before?! This is perfect for ya!&lt;/p&gt;

&lt;p&gt;Let's start with a few concepts of setting up and using the Canvas API. We can think of Canvas as a programmable etch a sketch that you erase and draw every time at a fraction of a second.&lt;/p&gt;

&lt;p&gt;We can setup the first few lines of code in HTML, CSS, and JavaScript. We'll use CodePen because it's an easy way to jump in and start building with Canvas. You'll create a new pen, set CSS to normalize, add &lt;code&gt;&amp;lt;canvas id="canvas"&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/code&gt; to the HTML, and add &lt;code&gt;html { overflow: hidden; }&lt;/code&gt; to CSS.&lt;/p&gt;

&lt;p&gt;Now we can get into building with Canvas, breaking down each step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const canvas = document.querySelector("#canvas");
const context = canvas.getContext("2d");
let canvasWidth = canvas.width = window.innerWidth;
let canvasHeight = canvas.height = window.innerHeight;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We'll store a reference to the HTMLCanvasElement with &lt;code&gt;const canvas = document.querySelector("#canvas");&lt;/code&gt; this will let us access properties and methods to start drawing. &lt;code&gt;const context = canvas.getContext("2d");&lt;/code&gt; reaches into the canvas HTMLCanvasElement to return the context of the canvas to draw. &lt;code&gt;canvasWidth&lt;/code&gt; and &lt;code&gt;canvasHeight&lt;/code&gt; are using the properties of the window to apply the width and height to the canvas.&lt;/p&gt;

&lt;p&gt;First let's build the &lt;code&gt;render&lt;/code&gt; function to set the color for the &lt;code&gt;context&lt;/code&gt; then draw a shape &lt;code&gt;fillRect()&lt;/code&gt; as the background.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function render(){
  context.fillStyle = 'lightsalmon';
  context.fillRect(0, 0, canvasWidth, canvasHeight);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we can construct a class for a shape, let's make it a Square ◻️ and give it these properties in the constructor &lt;code&gt;{ width, height, rotate, xPosition, yPosition }&lt;/code&gt;. We'll deconstruct the incoming object in the constructor and set default values. After making the Square class let's make an instance of Square and set some properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Square {
  constructor({
    width,
    height,
    rotate = 0,
    xPosition = canvasWidth / 2,
    yPosition = canvasHeight / 2
  }) {
    this.width = width;
    this.height = height;
    this.rotate = rotate;
    this.xPosition = xPosition;
    this.yPosition = yPosition;
  }
}

const square = new Square({width: 50, height: 50});
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have the Square class and an instance of it created. We can start to add it to the render method. So let's step back into it and do a few important steps. The &lt;code&gt;context.save()&lt;/code&gt; method will allow us to save the transformation, specific attributes, clipping, etc. Allowing you to place multiple shapes in the drawing context of canvas and &lt;code&gt;context.restore()&lt;/code&gt; will reinstate the state from &lt;code&gt;context.save()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function render() {
  context.fillStyle = "lightsalmon";
  context.fillRect(0, 0, canvasWidth, canvasHeight);
  context.save();
  // Add styling for square in the context here!
  context.restore();
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Nothing is going to change when setting this up but it will allow us to start building in the shapes and styles in the commented section! So let's add a darker color to next draw context &lt;code&gt;context.fillStyle&lt;/code&gt;, set the context transformation matrix with &lt;code&gt;context.translate()&lt;/code&gt;, &lt;code&gt;context.rotate()&lt;/code&gt;, then draw in the context with &lt;code&gt;context.fillRect()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function render() {
  context.fillStyle = "lightsalmon";
  context.fillRect(0, 0, canvasWidth, canvasHeight);
  // animation method
  context.save();
  context.fillStyle = "salmon";
  context.translate(square.xPosition, square.yPosition);
  context.rotate(square.rotate);
  context.fillRect(-square.width/2, -square.height/2, square.width, square.height);
  context.restore();
  // requestAnimationFrame
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Awesome! You drew a shape in the canvas... now let's animate it! We'll create a movement method to increment the rotation and position of the &lt;code&gt;square&lt;/code&gt;. The transformation matrix property &lt;code&gt;rotate&lt;/code&gt; is a value of 0 to 1; 1 represents 360 degrees. Where we place the movement method to manipulate the &lt;code&gt;square&lt;/code&gt; properties will be very important.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function movement(shape) {
  shape.rotate += 0.01;
  shape.xPosition += 0.1;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Since we have the movement method, let's start by building it into the render method. The most important thing is we need to make sure we're not constantly updating the context transformation matrix every time movement method occurs. So &lt;code&gt;context.save&lt;/code&gt; makes sure that doesn't happen and &lt;code&gt;context.restore&lt;/code&gt; applies the initial state again. The last thing we'll do it use the requestAnimationFrame method so we're only calling the render method every 60 frames a second :D&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function render() {
  context.fillStyle = "lightsalmon";
  context.fillRect(0, 0, canvasWidth, canvasHeight);
  movement(square);
  context.save();
  context.fillStyle = "salmon";
  context.translate(square.xPosition, square.yPosition);
  context.rotate(square.rotate);
  context.fillRect(-square.width/2, -square.height/2, square.width, square.height);
  context.restore();
  window.requestAnimationFrame(render);
}

window.requestAnimationFrame(render);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There we go! The square is slowly rotating and flying off the canvas! You can check out the final version on CodePen :D&lt;/p&gt;

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

</description>
      <category>javascript</category>
      <category>codepen</category>
      <category>tutorial</category>
      <category>creativecoding</category>
    </item>
    <item>
      <title>Web Animation API-llusion of Life</title>
      <dc:creator>Brian Montana</dc:creator>
      <pubDate>Wed, 26 Jun 2019 19:21:52 +0000</pubDate>
      <link>https://dev.to/brianmontanaweb/web-animation-api-llusion-of-life-2mg6</link>
      <guid>https://dev.to/brianmontanaweb/web-animation-api-llusion-of-life-2mg6</guid>
      <description>&lt;h1&gt;
  
  
  12 Basic Principles of Animation
&lt;/h1&gt;

&lt;p&gt;Let’s begins with the basics of animation from The Illusion of Life by Frank Thomas and Ollie Johnston, who worked at Disney as animators, they defined the foundations of animation in 12 concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Squash and Stretch:&lt;/strong&gt;&lt;br&gt;
Giving a physicality to elements so the motion is dictated in a consistent state of physics; realistic or imaginative. Pulling and pushing a visual, sometimes bouncing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Anticipation:&lt;/strong&gt;&lt;br&gt;
Preparing a user for a change in visual state or large shift in presentation. Signaling through light motion before a bigger action happens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Staging:&lt;/strong&gt;&lt;br&gt;
A clear state or direction for the user on what is happening, easy to identify at a quick glace. Reference to theater or spotlight focus on a component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pose to Pose or Straight Ahead:&lt;/strong&gt;&lt;br&gt;
Building the key frames by programming the transition between them so it feels natural in the product.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Follow through:&lt;/strong&gt;&lt;br&gt;
Components with multiple parts can react to the motion by continuing and snapping back when the component breaks into place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Slow in &amp;amp; Slow out:&lt;/strong&gt;&lt;br&gt;
Easing in or out of an animation, changing the value’s over time to enter with a lower value over a longer time or enter faster with a lower value. Visualized as a graph with Y of time and X as value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arcs:&lt;/strong&gt;&lt;br&gt;
Giving the entrance or exit of a component a curved path or change in positioning from start to finish, giving it personality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secondary Action:&lt;/strong&gt;&lt;br&gt;
Action that reacts to an entrance or exit. Component entering collides with another, the content inside responds by moving too but at a staggered or reduced motion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Timing:&lt;/strong&gt;&lt;br&gt;
Slow actions when a user is required to wait for a server response(or related scenarios) and faster actions when components/data are being populated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exaggeration:&lt;/strong&gt;&lt;br&gt;
Making the component’s animation larger than life to call attention or show it’s purpose sometimes giving it scale, extra squash/stretch, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solid Drawings:&lt;/strong&gt;&lt;br&gt;
3D can give weight and prominence to components when animating.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Appeal:&lt;/strong&gt;&lt;br&gt;
Define an physical environment for the components to react in when determining gravity, weight, movement, dimension, etc to get users engaged and directing them around the product. Makes components appear interesting.&lt;/p&gt;

&lt;p&gt;The video shows the visuals of animations by giving a cube personality through all of the rule sets.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/93206523" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;a href="https://vimeo.com/93206523"&gt;The illusion of life&lt;/a&gt; from &lt;a href="https://vimeo.com/centodesign"&gt;cento lodigiani&lt;/a&gt; on &lt;a href="https://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here are some CSS animations that cover the basic principles of animation, squishy squishy buttons!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/brianmontanaweb/embed/wpKYwP?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
Building basic animations principles concepted by Disney Studios&lt;/p&gt;

&lt;p&gt;Motion, when defined consistently in visuals will convey the intentions of the work presented to the viewer/audience. These concepts can be built in any medium that includes a time component: video, animation, motion design, games, web, apps, music video, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/VkTB7OIqEqTba/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/VkTB7OIqEqTba/giphy.gif" alt="Jamiroquai in a room with moving floor."&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Web Animation API (WAAPI)
&lt;/h2&gt;

&lt;p&gt;Allows for a synchronizing and timing of websites for animating DOM elements. The Timing Model and Animation Model are combined in this API so browsers have a common language for animations.&lt;/p&gt;

&lt;p&gt;A few stumbles for translating animations from CSS to WAAPI. Avoid pseudo element animations and focus on the component/element level of animation. Be aware of how the animation impacts elements it’s applied to by testing different presentations and states. Static animations that maintain a component’s integrity when applied don’t need to use WAAPI, if it doesn’t change a lot keep it in CSS. WAAPI requires a polyfill for newer features but you can use the first implementation in Chrome and FireFox. Later features are in the polyfill and very much worth trying.&lt;/p&gt;

&lt;p&gt;Reasons why you want to consider WAAPI. If there’s a need to update the animation on the fly with randomized/generated values, this is perfect. You won’t need bloated SCSS/Sass mixins and functions that generate a lot of code. Building out an animation timeline that needs dynamic responses based on user input. WAAPI still uses the benefits of CSS performance optimization. You can handle animations in JS without statically setting up animations in a stylesheet that can’t be updated without JS or changing/updating the stylesheets. Live in the future today.&lt;/p&gt;
&lt;h2&gt;
  
  
  WAAPI animate method
&lt;/h2&gt;

&lt;p&gt;The first method you can start using is &lt;code&gt;Element.animate()&lt;/code&gt;. Let’s break down the key frames and options: &lt;code&gt;element.animate(keyframes, options)&lt;/code&gt;. &lt;code&gt;keyframes&lt;/code&gt; can be an object or array of object key-value pairs for animating element styles.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;element.animate([arrayFrames] || {objectFrame}, {options})&lt;/code&gt; method creates a new &lt;code&gt;Animation&lt;/code&gt; object instance to build out the frames needed for your animation. The frames are positioned according to where they are in the index order &lt;code&gt;[0%, 100%] || [0%, 33%, 66%, 100%]&lt;/code&gt; you can define &lt;code&gt;offset&lt;/code&gt; in the frame to position the frame in the timeline.&lt;/p&gt;

&lt;p&gt;CSS animations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.class-thing {
  transform: scale(1, 1);
  animation: 4s infinite squash-stretch; 
}

@keyframes squash-stretch {
  92% {
    transform: scale(1, 1);
  }
  94% {
    transform: scale(1.75, 0.5);
  }
  100% {
    transform: scale(1, 1);
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Web Animation API animations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.animate([{
   transform: ‘scale(1, 1)’
 }, {
   transform: ‘scale(1, 1)’,
   offset: 0.92
 }, {
   transform: ‘scale(1.75, 0.5)’,
   offset: 0.94
 }, {
   transform: ‘scale(1, 1)’,
   offset: 1
 }], {
   duration: 4000,
   iterations: Infinity
 });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Moving the start of the animation from CSS portions that might not cascade properly in larger products into the JavaScript help with unique and componentized approach to motion design in web/apps. A big thing to note is you need to use the same styles frame to frame for the first implementation of WAAPI, this issue gets resolved in the polyfill and next implementation.&lt;/p&gt;

&lt;p&gt;This can throw an error! ACK!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element.animate([{
   transform: ‘scale(1, 1)’,
   //The backgroundColor isn't in any other frame and will throw an error with WAAPI, careful!
   backgroundColor: 'red'
 }, {
   transform: ‘scale(1, 1)’,
   offset: 0.92
 }, {
   transform: ‘scale(1.75, 0.5)’,
   offset: 0.94
 }, {
   transform: ‘scale(1, 1)’,
   offset: 1
 }], {
   duration: 4000,
   iterations: Infinity
 });
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;.animate Options&lt;/p&gt;

&lt;p&gt;Check out the &lt;code&gt;animate&lt;/code&gt; method options at MDN or the W3C spec, version one is currently working in a few browsers but recommend using the polyfill for better feature support. I’ll note a few issues with options in the first implementation that are/will be resolved in future updates and currently with the polyfill. Can’t access animate options after construction but you will be able to with &lt;code&gt;element.animate(frames, options).effect.timing&lt;/code&gt;. Delay evaluates &lt;code&gt;1000&lt;/code&gt; and &lt;code&gt;'1000'&lt;/code&gt; the same in Chrome and FF but duration only accepts integers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple Animations
&lt;/h2&gt;

&lt;p&gt;Building out multiple animations dynamically using JS. You can see in the example the delay is built to stagger the animations and the delay is updated when the user clicks an image and it resets the animation to the start. When updating the animation frames they don’t overwrite the entire frame but the property.&lt;/p&gt;

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

&lt;p&gt;The images fly in from the side and when finishing the animation a class is removed and you can control the timing on the NodeList of images while resetting or updating the options and frames dynamically!&lt;/p&gt;

&lt;p&gt;Thanks for reading and if there’s anything I should update let me know. I’ll be exploring WAAPI even more :D&lt;br&gt;
Sources/credit:&lt;/p&gt;

&lt;p&gt;Rachel Nabors — &lt;a href="http://codepen.io/collection/bpEza/"&gt;Alice in Web Animation Land&lt;/a&gt;&lt;br&gt;
Val Head — &lt;a href="https://www.fastcodesign.com/3055811/what-disneys-classic-animation-principles-can-teach-us-about-great-web-design"&gt;What Disney’s Classic Animation Principles Could Teach Web Designers&lt;/a&gt;&lt;br&gt;
Daniel C Wilson — &lt;a href="http://danielcwilson.com/blog/2015/07/animations-intro/"&gt;Animations Intro&lt;/a&gt;&lt;br&gt;
Web Animation API — &lt;a href="https://github.com/web-animations/web-animations-js"&gt;web-animations-js&lt;/a&gt;&lt;br&gt;
W3C — &lt;a href="https://drafts.csswg.org/web-animations/"&gt;Web Animation Spec&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>showdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
