Welcome, Guest

Author Topic: UI animations framework for Coherent UI (PART4)  (Read 1542 times)

Billy

  • Administrator
  • *****
  • Posts: 41
    • View Profile
UI animations framework for Coherent UI (PART4)
« on: October 23, 2014, 01:56:27 AM »
Hi there, today we present Part 4 of UI animations framework for Coherent UI. If you want to recall Part 1 , Part 2 and Part 3 before you go on with the tutorial follow the links.

We are very proud to announce that the Coherent Animation library is almost ready and will be available in Coherent UI 2.5. The library gives an easy framework where UI developers can create complex animations and interactions with JavaScript code. Developers can use the code in conjunction with any visual HTML5 editing tool.



This post will be a simple tutorial where we’ll show you how to create a small animation in order to give a taste of the API. We will use only code, but in later posts we will show how to integrate the library into various tools such as Adobe Edge Animate.

The animation represents a moving div element, which comes from the left to the current css definition of it.

Let’s define the css property of the element.

Code: [Select]
#rect {
position: absolute;
  top: 50px;
  left: 250px;
  width: 200px;
  height: 200px;
  background: #000;
}

This css code will create a black rectangle which will be positioned “absolute” against the page body tag. The current position of our element is: left 250px and top 50px.
Our idea is to show how easily you can animate movement starting from left:0, going to the current 250px and then from top:0 moving to top: 50px.

The snippet of this animation definition follows a syntax:

JavaScript

Code: [Select]
var moveRect = [
  {percent: 0.5, left:0},
  {percent: 1, top: 0}
]

The property percent in our object will be a segment of our time in seconds, when we call the method, which will run the animation.
See below: the properties left and top will apply.

The next step is to create a new CoherentAnimation object.
Code: [Select]
var anim1 = new CoherentAnimation();

After that, we have to push an object in caFrom method.

The object follows a syntax:

JavaScript

Code: [Select]
anim1.caFrom({
  selector: '#rect',
  anims: moveRect,
  seconds: 2
}).play()

In this sample, the object we are pushing has the following properties:
  • selector: selects our element by id
  • anims: it takes an object or array of objects.
  • seconds: This is the duration of animation in seconds. This property is optional. We could use it only if we want to declare a percent based animation. In our case we say that when the whole animation is 2 seconds, during the first second (0.5 percent) we will move the element from left:0 to left 250px; If we declare the animation duration to be 4 seconds, then the 0.5 percent will be 2 seconds.

In the end we call play() method, which will run the animation. By default animation is always on pause and for that reason we have to call play() at the end.



This was a very simple example how to create an animation. We will continue with an in-depth look on the usage of the Coherent Animation library in upcoming posts.


Tags: