.net3.5 和vs2008中Ajax控件的使用--Animation(信息浮动面板)控件(post)

一、我们使用一个简单的例子来说明Animation的一些属性。

a、新建Ajax Web窗体,命名为Animation.aspx。

b、在Animation窗体上拖放一个panel控件,代码如下:

  1. <asp:Panel ID="Panel1" runat="server">   
  2.   
  3.     <div style="width:100px; height:200px; background-color:Green;">sdfsfsfsdfsf   
  4.   
  5.     sdfsfsdfs</div>   
  6.   
  7.     </asp:Panel>  

c、为该panel控件添加扩展程序,即添加Animation控件:

在源代码页面就添加了一个Animation控件

  1. <cc1:AnimationExtender ID="Panel1_AnimationExtender" runat="server"    
  2.   
  3.        Enabled="True" TargetControlID="Panel1">   
  4.   
  5.          
  6.   
  7.    </cc1:AnimationExtender>  

 我们为Animation添加相关的属性和事件

  1. <cc1:AnimationExtender ID="Panel1_AnimationExtender" runat="server"    
  2.   
  3.         Enabled="True" TargetControlID="Panel1">   
  4.   
  5.         <Animations>   
  6.   
  7.         <OnClick>   
  8.   
  9.       <FadeOut Duration=".5" Fps="20" />   
  10.   
  11.    </OnClick>   
  12.   
  13.   </Animations>   
  14.   
  15.     </cc1:AnimationExtender>  

在这里我们实现了一个简单的功能:点击panel,panel消失。属性说明如下:

Aniamtions节是所有Animations声明和使用的地方

onclick节指出当目标控件被点击,其中的动画效果会发生

Fadeout节是具体要发生的动画效果

效果如下:

点击panel前:

点击后,panel消失。

二、点击按钮的效果实现实例。

a、在页面上拖放一个button控件,然后在页面上放几个div,目的是点击按钮后显示div内容。代码如下:

b、为刚建立的button建立Animation扩展程序

c、为Animation控件设置相关的属性和事件,代码如下:

  1. <cc1:AnimationExtender ID="Button1_AnimationExtender" runat="server"    
  2.   
  3.         Enabled="True" TargetControlID="Button1">   
  4.   
  5.          <Animations>   
  6.   
  7.                 <OnClick>   
  8.   
  9.                     <Sequence>   
  10.   
  11.                         <%-- Disable the button so it can't be clicked again --%>   
  12.   
  13.                         <EnableAction Enabled="false" />   
  14.   
  15.                            
  16.   
  17.                         <%-- Position the wire frame on top of the button and show it --%>   
  18.   
  19.                         <ScriptAction Script="Cover($get('ctl00_SampleContent_btnInfo'), $get('flyout'));" />   
  20.   
  21.                         <StyleAction AnimationTarget="flyout" Attribute="display" Value="block"/>   
  22.   
  23.                            
  24.   
  25.                         <%-- Move the wire frame from the button's bounds to the info panel's bounds --%>   
  26.   
  27.                         <Parallel AnimationTarget="flyout" Duration=".3" Fps="25">   
  28.   
  29.                             <Move Horizontal="150" Vertical="-50" />   
  30.   
  31.                             <Resize Width="260" Height="280" />   
  32.   
  33.                             <Color PropertyKey="backgroundColor" StartValue="#AAAAAA" EndValue="#FFFFFF" />   
  34.   
  35.                         </Parallel>   
  36.   
  37.                            
  38.   
  39.                         <%-- Move the info panel on top of the wire frame, fade it in, and hide the frame --%>   
  40.   
  41.                         <ScriptAction Script="Cover($get('flyout'), $get('info'), true);" />   
  42.   
  43.                         <StyleAction AnimationTarget="info" Attribute="display" Value="block"/>   
  44.   
  45.                         <FadeIn AnimationTarget="info" Duration=".2"/>   
  46.   
  47.                         <StyleAction AnimationTarget="flyout" Attribute="display" Value="none"/>   
  48.   
  49.                            
  50.   
  51.                         <%-- Flash the text/border red and fade in the "close" button --%>   
  52.   
  53.                         <Parallel AnimationTarget="info" Duration=".5">   
  54.   
  55.                             <Color PropertyKey="color" StartValue="#666666" EndValue="#FF0000" />   
  56.   
  57.                             <Color PropertyKey="borderColor" StartValue="#666666" EndValue="#FF0000" />   
  58.   
  59.                         </Parallel>   
  60.   
  61.                         <Parallel AnimationTarget="info" Duration=".5">   
  62.   
  63.                             <Color PropertyKey="color" StartValue="#FF0000" EndValue="#666666" />   
  64.   
  65.                             <Color PropertyKey="borderColor" StartValue="#FF0000" EndValue="#666666" />   
  66.   
  67.                             <FadeIn AnimationTarget="btnCloseParent" MaximumOpacity=".9" />   
  68.   
  69.                         </Parallel>   
  70.   
  71.                     </Sequence>   
  72.   
  73.                 </OnClick>   
  74.   
  75.             </Animations>   
  76.   
  77.     </cc1:AnimationExtender>  

节点说明:

1、<Sequence>  </Sequence> 顺序执行的动画脚本

2、<Parallel>  <Parallel >  并发执行的动画脚本

3、<EnableAction Enabled="false" />控件是否可用

4、<ScriptAction Script="Cover($get('ctl00_SampleContent_btnInfo'), $get('flyout'));" />执行一段脚本的 Action

5、<Color PropertyKey="color" StartValue="#666666" EndValue="#FF0000" />颜色渐变效果,设置起始结束颜色就可以

6、<FadeIn AnimationTarget="info" Duration=".2"/>淡入效果,对应<FadeOut />淡出效果。

还有一个相关的属性就不一一说明了,请读者尝试。

d、效果如下:

e、我们可以看到点击按钮后,div不能关闭,我们可以在右上角加一个linkbutton按钮,同样增加一个Animation控件来控制div的关闭,这里就不具体介绍了,代码如下:

  1. <cc1:AnimationExtender ID="AnimationExtender2" runat="server"    
  2.   
  3.         Enabled="True" TargetControlID="btnClose">   
  4.   
  5.         <Animations>   
  6.   
  7.                 <OnClick>   
  8.   
  9.                     <Sequence AnimationTarget="info">   
  10.   
  11.                         <%--  Shrink the info panel out of view --%>   
  12.   
  13.                         <StyleAction Attribute="overflow" Value="hidden"/>   
  14.   
  15.                         <Parallel Duration=".3" Fps="15">   
  16.   
  17.                             <Scale ScaleFactor="0.05" Center="true" ScaleFont="true" FontUnit="px" />   
  18.   
  19.                             <FadeOut />   
  20.   
  21.                         </Parallel>   
  22.   
  23.                            
  24.   
  25.                         <%--  Reset the sample so it can be played again --%>   
  26.   
  27.                         <StyleAction Attribute="display" Value="none"/>   
  28.   
  29.                         <StyleAction Attribute="width" Value="250px"/>   
  30.   
  31.                         <StyleAction Attribute="height" Value=""/>   
  32.   
  33.                         <StyleAction Attribute="fontSize" Value="12px"/>   
  34.   
  35.                         <OpacityAction AnimationTarget="btnCloseParent" Opacity="0" />   
  36.   
  37.                            
  38.   
  39.                         <%--  Enable the button so it can be played again --%>   
  40.   
  41.                         <EnableAction AnimationTarget="btnInfo" Enabled="true" />   
  42.   
  43.                     </Sequence>   
  44.   
  45.                 </OnClick>   
  46.   
  47.                 <OnMouseOver>   
  48.   
  49.                     <Color Duration=".2" PropertyKey="color" StartValue="#FFFFFF" EndValue="#FF0000" />   
  50.   
  51.                 </OnMouseOver>   
  52.   
  53.                 <OnMouseOut>   
  54.   
  55.                     <Color Duration=".2" PropertyKey="color" StartValue="#FF0000" EndValue="#FFFFFF" />   
  56.   
  57.                 </OnMouseOut>   
  58.   
  59.              </Animations>   
  60.   
  61.         </cc1:AnimationExtender>  

f、最终的效果如下:

三、附上完整代码

  1. <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return false;"  />   
  2.   
  3.      
  4.   
  5.       
  6.   
  7.     <div id="flyout" style="display: none; width:250px; overflow: hidden; z-index: 2; background-color: #FFFFFF; border: solid 1px #D0D0D0;"></div>   
  8.   
  9.           
  10.   
  11.        <!-- Info panel to be displayed as a flyout when the button is clicked -->   
  12.   
  13.        <div id="info" style="display: none; width: 250px; z-index: 2; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); font-size: 12px; border: solid 1px #CCCCCC; background-color: #FFFFFF; padding: 5px;">   
  14.   
  15.            <div id="btnCloseParent" style="float: right; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);">   
  16.   
  17.                <asp:LinkButton id="btnClose" runat="server" OnClientClick="return false;" Text="X" ToolTip="Close"  
  18.   
  19.                    Style="background-color: #666666; color: #FFFFFF; text-align: center; font-weight: bold; text-decoration: none; border: outset thin #FFFFFF; padding: 5px;" />   
  20.   
  21.            </div>   
  22.   
  23.            <div>   
  24.   
  25.                <p>   
  26.   
  27.                    Once you get the general idea of the animation's markup, you'll want to play a bit.  All of   
  28.   
  29.                    the animations are created from simple, reusable building blocks that you can compose together.   
  30.   
  31.                    Before long you'll be creating dazzling visuals.  By grouping steps together and specifying   
  32.   
  33.                    them to be run either in sequence or in parallel, you'll achieve almost anything you can   
  34.   
  35.                    imagine, without writing a single line of code!   
  36.   
  37.                </p>   
  38.   
  39.                <br />   
  40.   
  41.                <p>   
  42.   
  43.                    The XML defining the animations is very easy to learn and write, such as this example's   
  44.   
  45.                    markup.   
  46.   
  47.                </p>   
  48.   
  49.            </div>   
  50.   
  51.        </div>   
  52.   
  53.          <cc1:AnimationExtender ID="Button1_AnimationExtender" runat="server"    
  54.   
  55.        Enabled="True" TargetControlID="Button1">   
  56.   
  57.         <Animations>   
  58.   
  59.                <OnClick>   
  60.   
  61.                    <Sequence>   
  62.   
  63.                        <%-- Disable the button so it can't be clicked again --%>   
  64.   
  65.                        <EnableAction Enabled="false" />   
  66.   
  67.                           
  68.   
  69.                        <%-- Position the wire frame on top of the button and show it --%>   
  70.   
  71.                        <ScriptAction Script="Cover($get('ctl00_SampleContent_btnInfo'), $get('flyout'));" />   
  72.   
  73.                        <StyleAction AnimationTarget="flyout" Attribute="display" Value="block"/>   
  74.   
  75.                           
  76.   
  77.                        <%-- Move the wire frame from the button's bounds to the info panel's bounds --%>   
  78.   
  79.                        <Parallel AnimationTarget="flyout" Duration=".3" Fps="25">   
  80.   
  81.                            <Move Horizontal="150" Vertical="-50" />   
  82.   
  83.                            <Resize Width="260" Height="280" />   
  84.   
  85.                            <Color PropertyKey="backgroundColor" StartValue="#AAAAAA" EndValue="#FFFFFF" />   
  86.   
  87.                        </Parallel>   
  88.   
  89.                           
  90.   
  91.                        <%-- Move the info panel on top of the wire frame, fade it in, and hide the frame --%>   
  92.   
  93.                        <ScriptAction Script="Cover($get('flyout'), $get('info'), true);" />   
  94.   
  95.                        <StyleAction AnimationTarget="info" Attribute="display" Value="block"/>   
  96.   
  97.                        <FadeIn AnimationTarget="info" Duration=".2"/>   
  98.   
  99.                        <StyleAction AnimationTarget="flyout" Attribute="display" Value="none"/>   
  100.   
  101.                           
  102.   
  103.                        <%-- Flash the text/border red and fade in the "close" button --%>   
  104.   
  105.                        <Parallel AnimationTarget="info" Duration=".5">   
  106.   
  107.                            <Color PropertyKey="color" StartValue="#666666" EndValue="#FF0000" />   
  108.   
  109.                            <Color PropertyKey="borderColor" StartValue="#666666" EndValue="#FF0000" />   
  110.   
  111.                        </Parallel>   
  112.   
  113.                        <Parallel AnimationTarget="info" Duration=".5">   
  114.   
  115.                            <Color PropertyKey="color" StartValue="#FF0000" EndValue="#666666" />   
  116.   
  117.                            <Color PropertyKey="borderColor" StartValue="#FF0000" EndValue="#666666" />   
  118.   
  119.                            <FadeIn AnimationTarget="btnCloseParent" MaximumOpacity=".9" />   
  120.   
  121.                        </Parallel>   
  122.   
  123.                    </Sequence>   
  124.   
  125.                </OnClick>   
  126.   
  127.            </Animations>   
  128.   
  129.    </cc1:AnimationExtender>   
  130.   
  131.     <cc1:AnimationExtender ID="AnimationExtender2" runat="server"    
  132.   
  133.        Enabled="True" TargetControlID="btnClose">   
  134.   
  135.        <Animations>   
  136.   
  137.                <OnClick>   
  138.   
  139.                    <Sequence AnimationTarget="info">   
  140.   
  141.                        <%--  Shrink the info panel out of view --%>   
  142.   
  143.                        <StyleAction Attribute="overflow" Value="hidden"/>   
  144.   
  145.                        <Parallel Duration=".3" Fps="15">   
  146.   
  147.                            <Scale ScaleFactor="0.05" Center="true" ScaleFont="true" FontUnit="px" />   
  148.   
  149.                            <FadeOut />   
  150.   
  151.                        </Parallel>   
  152.   
  153.                           
  154.   
  155.                        <%--  Reset the sample so it can be played again --%>   
  156.   
  157.                        <StyleAction Attribute="display" Value="none"/>   
  158.   
  159.                        <StyleAction Attribute="width" Value="250px"/>   
  160.   
  161.                        <StyleAction Attribute="height" Value=""/>   
  162.   
  163.                        <StyleAction Attribute="fontSize" Value="12px"/>   
  164.   
  165.                        <OpacityAction AnimationTarget="btnCloseParent" Opacity="0" />   
  166.   
  167.                           
  168.   
  169.                        <%--  Enable the button so it can be played again --%>   
  170.   
  171.                        <EnableAction AnimationTarget="btnInfo" Enabled="true" />   
  172.   
  173.                    </Sequence>   
  174.   
  175.                </OnClick>   
  176.   
  177.                <OnMouseOver>   
  178.   
  179.                    <Color Duration=".2" PropertyKey="color" StartValue="#FFFFFF" EndValue="#FF0000" />   
  180.   
  181.                </OnMouseOver>   
  182.   
  183.                <OnMouseOut>   
  184.   
  185.                    <Color Duration=".2" PropertyKey="color" StartValue="#FF0000" EndValue="#FFFFFF" />   
  186.   
  187.                </OnMouseOut>   
  188.   
  189.             </Animations>   
  190.   
  191.        </cc1:AnimationExtender>   
  192.   
  193.        <script type="text/javascript" language="javascript">   
  194.   
  195.            // Move an element directly on top of another element (and optionally   
  196.   
  197.            // make it the same size)   
  198.   
  199.            function Cover(bottom, top, ignoreSize) {   
  200.   
  201.                var location = Sys.UI.DomElement.getLocation(bottom);   
  202.   
  203.                top.style.position = 'absolute';   
  204.   
  205.                top.style.top = location.y + 'px';   
  206.   
  207.                top.style.left = location.x + 'px';   
  208.   
  209.                if (!ignoreSize) {   
  210.   
  211.                    top.style.height = bottom.offsetHeight + 'px';   
  212.   
  213.                    top.style.width = bottom.offsetWidth + 'px';   
  214.   
  215.                }   
  216.   
  217.            }   
  218.   
  219.        </script> 
posted @ 2009-03-12 16:25  Devil_Zhang  阅读(636)  评论(0编辑  收藏  举报