This JS script comes from the general uninterrupted rolling JS encapsulation class compiled by Cui Yongxiang.
Or the first effect:
The HTML code is as follows:
The design process is as follows:
Drag and Drop the code to be rolled into the control.
It is set to scroll up, with a height of PX and a width of the current browser window.
Let's take a look at the preview effect to implement scrolling:
The following describes the control encoding process.
This time we inherit the webcontrol class, which is more convenient.
[ParseChildren(false)][ToolboxData("<{0}:MarqueeControl runat=server></{0}:MarqueeControl>")]public class MarqueeControl : WebControl
Here we will talk about the features of parsechildren,
Parsechildren (false) indicates that the elements in the control will be parsed into controls.
Parsechildren (true) indicates that the elements in the control will be parsed into properties ).
Constructor:
public MarqueeControl() : base(HtmlTextWriterTag.Div){ }
Make the generated HTML Tag Div.
The new attributes are as follows:
[Description ("scroll direction (scroll up by default)")] [typeconverter (typeof (directiontype)] public directiontype direction
[Description ("rolling step (default value: 2, greater value, faster scrolling)")] public int step
[Description ("timer (the default value is 50, the smaller the value, the faster the scroll speed, 1000 = 1 second, not less than 20)")] public int Timer
[Description ("interval pause delay time (0 by default, 1000 = 1 second)")] public int delaytime
[Description ("Start Time wait time (default or 0 is not waiting, 1000 = 1 second)")] public int waittime
[Description ("intermittent rolling interval (50 by default,-1 disables mouse control)")] public int scrollstep
[Description ("client name is clientid by default")] Public String clientinstancename
[Description ("client custom script")] Public String clientscript
I will not describe them one by one here. select a few.
The Property dialog box for direction design is as follows:
Becomes an optional item,
It is implemented through [typeconverter (typeof (directiontype.
Directiontype is an enumeration:
Public Enum directiontype {// <summary> // scroll down /// </Summary> Top = 0, /// <summary> /// scroll down /// </Summary> bottom = 1, /// <summary> /// scroll left /// </Summary> left = 2, /// <summary> /// scroll to the right /// </Summary> right = 3}
Clientinstancename is a marquee instance constructed by generating scripts. For example, VAR marq = new marquee ("ID ");
Clientscript is the script before rolling is enabled. You can write it by yourself.
The next step is to output the script code. The embedded control code will be automatically output without processing.
protected override void OnPreRender(EventArgs e){ if (!Page.ClientScript.IsClientScriptIncludeRegistered("MarqueeControlJS")) Page.ClientScript.RegisterClientScriptInclude("MarqueeControlJS", Page.ClientScript.GetWebResourceUrl(this.GetType(), "Hxj.Web.UI.js.marquee.js")); string clientName = this.ClientInstanceName; StringBuilder script = new StringBuilder(); script.AppendLine(); script.Append("var "); script.Append(clientName); script.Append("=new Marquee(\""); script.Append(this.ClientID); script.Append("\","); script.Append(this.Direction.GetHashCode().ToString()); script.Append(","); script.Append(this.Step.ToString()); script.AppendLine(");"); if (this.Width.Type == UnitType.Pixel) { script.Append(clientName); script.Append(".Width="); script.Append(this.Width.Value.ToString()); script.Append(";"); } if (this.Height.Type == UnitType.Pixel) { script.Append(clientName); script.Append(".Height="); script.Append(this.Height.Value.ToString()); script.Append(";"); } script.Append(clientName); script.Append(".Timer="); script.Append(this.Timer.ToString()); script.Append(";"); script.Append(clientName); script.Append(".DelayTime="); script.Append(this.DelayTime.ToString()); script.Append(";"); script.Append(clientName); script.Append(".WaitTime="); script.Append(this.WaitTime.ToString()); script.Append(";"); script.Append(clientName); script.Append(".ScrollStep="); script.Append(this.ScrollStep.ToString()); script.AppendLine(";"); if (!string.IsNullOrEmpty(ClientScript)) { script.AppendLine(ClientScript); } script.Append(clientName); script.AppendLine(".Start();"); if (!this.Page.ClientScript.IsStartupScriptRegistered("MarqueeControlStartscript" + this.ClientID)) this.Page.ClientScript.RegisterStartupScript(typeof(string), "MarqueeControlStartscript" + this.ClientID, script.ToString(), true); base.OnPreRender(e);}
You can also use js to change the rolling effect on the client as needed.
This way, you can write a non-gap scroll control.
Download