BorderAnimation = function(color) { this ._color = color; } BorderAnimation.prototype = { animate: function(panelElement) { var s = panelElement.style; s.borderWidth = ' 2px ' ; s.borderColor = this ._color; s.borderStyle = ' solid ' ; window.setTimeout( function() {{ s.borderWidth = 0 ; }}, 500 ); } }
using System; using System.Drawing; using System.Web.UI; using System.Web; using System.Globalization; namespace MySampleControl { public class UpdatePanelAnimationWithClientResource : Control { private string _updatePanelID; private Color _borderColor; private Boolean _animate; public Color BorderColor{ get { return _borderColor; } set {_borderColor = value; } } public string UpdatePanelID { get { return _updatePanelID; } set {_updatePanelID = value; } } public Boolean Animate { get { return _animate; } set {_animate = value; } } protected override void OnPreRender(EventArgs e) { base .OnPreRender(e); if (Animate) { UpdatePanel updatePanel = (UpdatePanel)FindControl(UpdatePanelID); string script = String.Format( CultureInfo.InvariantCulture, @" Sys.Application.add_load(function(sender, args) {{ var {0}_borderAnimation = new BorderAnimation('{1}'); var panelElement = document.getElementById('{0}'); if (args.get_isPartialLoad()) {{ {0}_borderAnimation.animate(panelElement); }} }}) " , updatePanel.ClientID, ColorTranslator.ToHtml(BorderColor)); ScriptManager.RegisterStartupScript( this , typeof (UpdatePanelAnimationWithClientResource), ClientID, script, true ); } } } }
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " Default.aspx.cs " Inherits = " _Default " %> <% @ Register TagPrefix = " Samples " Namespace = " MySampleControl " Assembly = " MySampleControl " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > Untitled Page </ title > </ head > < body > < form id ="form1" runat ="server" > < asp:ScriptManager ID ="ScriptManager1" runat ="server" > < Scripts > < asp:ScriptReference Assembly = " MySampleControl " Name = " MySampleControl.UpdatePanelAnimation.js " /> </ Scripts > </ asp:ScriptManager > < div > < Samples:UpdatePanelAnimationWithClientResource ID ="UpdatePanelAnimator1" BorderColor ="Green" Animate ="true" UpdatePanelID ="UpdatePanel1" runat ="server" > </ Samples:UpdatePanelAnimationWithClientResource > < asp:UpdatePanel ID ="UpdatePanel1" UpdateMode ="Conditional" runat ="server" > < ContentTemplate > < asp:Calendar ID ="Calendar2" runat ="server" > </ asp:Calendar > </ ContentTemplate > </ asp:UpdatePanel > </ div > </ form > </ body > </ html >
本文出自 “青峰” 博客,转载请与作者联系!