Adding Animation to a Control (VB)
The Animation control in the ASP.NET AJAX Control Toolkit is not just a control but a whole framework to add animations to a control. This tutorial shows how to set up such an animation.
Overview
The Animation control in the ASP.NET AJAX Control Toolkit is not just a control but a whole framework to add animations to a control. This tutorial shows how to set up such an animation.
Steps
The first step is as usual to include the ScriptManager
in the page so that the ASP.NET AJAX library is loaded and the Control Toolkit can be used:
[!code-aspxMain]
1: <asp:ScriptManager ID="asm" runat="server" />
The animation in this scenario will be applied to a panel of text which looks like this:
[!code-aspxMain]
1: <asp:Panel ID="panelShadow" runat="server" CssClass="panelClass">
2: ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient,
3: more interactive and highly-personalized Web experiences that work across all the
4: most popular browsers.<br />
5: ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient,
6: more interactive and highly-personalized Web experiences that work across all the
7: most popular browsers.<br />
8: ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient,
9: more interactive and highly-personalized Web experiences that work across all the
10: most popular browsers.<br />
11: </asp:Panel>
The associated CSS class for the panel defines a background color and a width:
[!code-cssMain]
1: <style type="text/css">
2: .panelClass {background-color: lime; width: 300px;}
3: </style>
Next up, we need the AnimationExtender
. After providing an ID
and the usual runat="server"
, the TargetControlID
attribute must be set to the control to animate in our case, the panel:
[!code-aspxMain]
1: <ajaxToolkit:AnimationExtender ID="ae" runat="server" TargetControlID="Panel1">
The whole animation is applied declaratively, using an XML syntax, unfortunately currently not fully supported by Visual Studio’s IntelliSense. The root node is <Animations>;
within this node, several events are allowed which determine when the animation(s) take(s) place:
OnClick
(mouse click)OnHoverOut
(when the mouse leaves a control)OnHoverOver
(when the mouse hovers over a control, stopping theOnHoverOut
animation)OnLoad
(when the page has been loaded)OnMouseOut
(when the mouse leaves a control)OnMouseOver
(when the mouse hovers over a control, not stopping theOnMouseOut
animation)
The framework comes with a set of animations, each one represented by its own XML element. Here is a selection:
<Color>
(changing a color)<FadeIn>
(fading in)<FadeOut>
(fading out)<Property>
(changing a control’s property)<Pulse>
(pulsating)<Resize>
(changing the size)<Scale>
(proportionally changing the size)
In this example, the panel shall fade out. The animation shall take 1.5 seconds (Duration
attribute), displaying 24 frames (animation steps) per second (Fps
attributs). Here is the complete markup for the AnimationExtender
control:
[!code-aspxMain]
1: <ajaxToolkit:AnimationExtender ID="ae" runat="server" TargetControlID="Panel1">
2: <Animations>
3: <OnLoad>
4: <FadeOut Duration="1.5" Fps="24" />
5: </OnLoad>
6: </Animations>
7: </ajaxToolkit:AnimationExtender>
When you run this script, the panel is displayed and fades out in one and a half seconds.
The panel is fading out (Click to view full-size image)
|