前台代码
1<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RollNews.ascx.cs" Inherits="Controls_RollNews" %>
2<div id="table01" style=" 300;">
3 <table width="158" height="420" border="0" cellpadding="0" cellspacing="0">
4 <tr>
5 <td width="<%=Width %>" height="420">
6 <font size="2">
7 <%=RollContent %>
8 </font>
9 </td>
10 </tr>
11 </table>
12</div>
13
14<script>
15marqueetable = document.all.table01;
16scrollheight=180; //滚动显示高度
17stopscroll1=false;
18marqueetable.scrollTop=0;
19
20with(marqueetable)
21{
22style.width='<%=Width %>';
23style.height=scrollheight;
24style.overflowX="hidden";
25style.overflowY="hidden";
26noWrap=true;
27onmouseover=new Function("stopscroll1=true");
28onmouseout=new Function("stopscroll1=false");
29}
30
31startmarqueetop=0;
32offsettop=1;
33marqueestoptime=0;
34//marqueetable.innerHTML+=marqueetable.innerHTML;
35
36function setmarqueetime()
37{
38marqueetable.scrollTop=0;
39setInterval("marqueeup()",'<%=RollTime %>');//设置滚动的时间
40}
41
42setmarqueetime();
43
44function marqueeup()
45{
46if(stopscroll1==true) return;
47offsettop+=1;
48
49if(offsettop==20)
50{
51marqueestoptime+=1;
52offsettop-=1;
53if(marqueestoptime=='<%=SleepTime %>') //停留的时间
54{
55 offsettop=0;
56marqueestoptime=0;
57}
58}
59else
60{
61 startmarqueetop=marqueetable.scrollTop;
62 marqueetable.scrollTop+=1;
63 if(startmarqueetop==marqueetable.scrollTop)
64 {
65 marqueetable.scrollTop=10;
66 marqueetable.scrollTop+=1;
67 }
68}
69}
70</script>
71
72
1<%@ Control Language="C#" AutoEventWireup="true" CodeFile="RollNews.ascx.cs" Inherits="Controls_RollNews" %>
2<div id="table01" style=" 300;">
3 <table width="158" height="420" border="0" cellpadding="0" cellspacing="0">
4 <tr>
5 <td width="<%=Width %>" height="420">
6 <font size="2">
7 <%=RollContent %>
8 </font>
9 </td>
10 </tr>
11 </table>
12</div>
13
14<script>
15marqueetable = document.all.table01;
16scrollheight=180; //滚动显示高度
17stopscroll1=false;
18marqueetable.scrollTop=0;
19
20with(marqueetable)
21{
22style.width='<%=Width %>';
23style.height=scrollheight;
24style.overflowX="hidden";
25style.overflowY="hidden";
26noWrap=true;
27onmouseover=new Function("stopscroll1=true");
28onmouseout=new Function("stopscroll1=false");
29}
30
31startmarqueetop=0;
32offsettop=1;
33marqueestoptime=0;
34//marqueetable.innerHTML+=marqueetable.innerHTML;
35
36function setmarqueetime()
37{
38marqueetable.scrollTop=0;
39setInterval("marqueeup()",'<%=RollTime %>');//设置滚动的时间
40}
41
42setmarqueetime();
43
44function marqueeup()
45{
46if(stopscroll1==true) return;
47offsettop+=1;
48
49if(offsettop==20)
50{
51marqueestoptime+=1;
52offsettop-=1;
53if(marqueestoptime=='<%=SleepTime %>') //停留的时间
54{
55 offsettop=0;
56marqueestoptime=0;
57}
58}
59else
60{
61 startmarqueetop=marqueetable.scrollTop;
62 marqueetable.scrollTop+=1;
63 if(startmarqueetop==marqueetable.scrollTop)
64 {
65 marqueetable.scrollTop=10;
66 marqueetable.scrollTop+=1;
67 }
68}
69}
70</script>
71
72
后台代码
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class Controls_RollNews : System.Web.UI.UserControl
13{
14 private string _RollContent = "";
15 private int _Width = 158;
16 private int _SleepTime=1;
17 private int _RollTime = 50;
18 public string RollContent
19 {
20 get { return _RollContent; }
21 set { _RollContent = value; }
22 }
23 public int Width
24 {
25 get { return _Width; }
26 set { _Width = value; }
27 }
28 public int SleepTime
29 {
30 get { return _SleepTime; }
31 set { _SleepTime = value; }
32 }
33 public int RollTime
34 {
35 get { return _RollTime; }
36 set { _RollTime = value; }
37 }
38 protected void Page_Load(object sender, EventArgs e)
39 {
40
41 }
42}
43
调用:1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class Controls_RollNews : System.Web.UI.UserControl
13{
14 private string _RollContent = "";
15 private int _Width = 158;
16 private int _SleepTime=1;
17 private int _RollTime = 50;
18 public string RollContent
19 {
20 get { return _RollContent; }
21 set { _RollContent = value; }
22 }
23 public int Width
24 {
25 get { return _Width; }
26 set { _Width = value; }
27 }
28 public int SleepTime
29 {
30 get { return _SleepTime; }
31 set { _SleepTime = value; }
32 }
33 public int RollTime
34 {
35 get { return _RollTime; }
36 set { _RollTime = value; }
37 }
38 protected void Page_Load(object sender, EventArgs e)
39 {
40
41 }
42}
43
<%@ Register Src="~/Controls/RollNews.ascx" TagName="RollNews" TagPrefix="ucRollNews" %>
<ucRollNews:RollNews ID="RollNews" runat="server" />
RollNews.RollContent = "古道西风长城外,夕阳西下漫山红。昨日相思今日忆,梦里几回换真心。共语情歌绕人肠,诗对切切费思量。几许真情言难诉,唯有真心驿动中。<br>";
<ucRollNews:RollNews ID="RollNews" runat="server" />
RollNews.RollContent = "古道西风长城外,夕阳西下漫山红。昨日相思今日忆,梦里几回换真心。共语情歌绕人肠,诗对切切费思量。几许真情言难诉,唯有真心驿动中。<br>";