The wijmo.animate Method

Animations can make web applications more attractive and intuitive. For example, removing an item from the page by making it shrink away lets the user see which item is being removed more easily that if it was simply hidden.

Many JavaScript toolkits and frameworks have their own wrappers for creating animations. For example, Angular has an $animate service, and jQuery has an animate() method. If you have a favorite you can use that with C1 MVC.

If you want to reduce dependencies on external toolkits and frameworks, you can use Wijmo's simple and flexible animate method instead.

The example below illustrates by rotating a FlexGrid like a flip card. The animate method has a single callback that controls the entire animation:

Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
US
Phones
145,248
81,732.54
38,401.13
1
Germany
Computers
111,632
20,603.32
27,944.24
2
UK
Cameras
181,205
44,217.79
48,877.49
3
Japan
Stereos
54,740
29,190.63
23,365.74
4
Italy
Phones
126,531
46,951.19
49,107.56
5
Greece
Computers
6,073
86,237.02
49,767.35
6
US
Cameras
135,436
31,459.18
40,845.40
7
Germany
Stereos
169,610
99,190.22
1,631.26
8
UK
Phones
139,988
52,628.41
46,700.93
9
Japan
Computers
137,524
54,681.54
4,055.50
10
Italy
Cameras
37,424
45,332.72
14,858.59
11
Greece
Stereos
197,708
64,269.75
38,148.18
12
US
Phones
6,078
38,100.45
17,157.09
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// This file locates: "Scripts/Lesson/C1Mvc/WijmoAnimate.js".
c1.documentReady(function () {
    var theGrid = wijmo.Control.getControl('#theGrid');
 
    // animate grid when user clicks the button
    document.getElementById('btnAnimate').addEventListener('click', function () {
        wijmo.animate(function (pct) {
 
            // calculate transform for given percent (zero to one)
            var xform = '';
            if (pct < 1) {
                if (pct > .5) pct = pct - 1;
                xform = 'rotateY( ' + (pct * 180) + 'deg)';
            }
 
            // apply the transform to the grid element
            theGrid.hostElement.style.transform = xform;
        }, 2000); // animate for two seconds
    })
});
1
2
3
4
// This file locates: "Content/css/Lesson/C1Mvc/WijmoAnimate.css".
.demo-control{
    perspective: 1000px;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1MvcController : Controller
    {
        // GET: WijmoAnimate
        public ActionResult WijmoAnimate()
        {
            return View(Models.FlexGridData.GetSales(100));
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@model IEnumerable<FlexGridData.Sale>
 
<h1>
    @Html.Raw(Resources.C1Mvc.WijmoAnimate_Title)
</h1>
<p>
    @Html.Raw(Resources.C1Mvc.WijmoAnimate_Text1)
</p>
<p>
    @Html.Raw(Resources.C1Mvc.WijmoAnimate_Text2)
</p>
<p>
    @Html.Raw(Resources.C1Mvc.WijmoAnimate_Text3)
</p>
<p>
    @Html.Raw(Resources.C1Mvc.WijmoAnimate_Text4)
</p>
<p>
    <button class="btn btn-default" id="btnAnimate">
        @Html.Raw(Resources.C1Mvc.WijmoAnimate_Text5)
    </button>
</p>
@Html.C1().FlexGrid().Id("theGrid").Bind(Model).Height(250)