PageSourceSearch

http://beichuan-machine.com/templets/default/images/MSClass.js

js beichuan-machine.com collected 2026-10-06 13:16:32 UTC 10,531 bytes, 291 lines download raw bytes

1<!--
2/*MSClass (Class Of Marquee Scroll通用不间断滚动JS封装类) Ver 1.6*\
3
4 制作时间:2006-08-29 (Ver 0.5)
5 发布时间:2006-08-31 (Ver 0.8)
6 更新时间:2007-01-31 (Ver 1.6)
7 更新说明: + 加入功能 * 修正、完善
8	1.6.070131
9		+ 禁止鼠标控制暂停或继续 (将第9个参数设置为-1或者动态赋值将ScrollSetp设置为-1)
10		+ 判断是否可以滚动 (若内容区域小于显示区域,则自动取消滚动)
11		+ 跳过初始化错误 (避免引起其它滚动的停止)
12		+ 默认值 (除容器ID必选外,其他参数均可根据情况进行选择设置)
13		+ 参数动态赋值 (方向可用英文表示top|bottom|left|right,使其更直观、方便)
14		* 文字滚动不准确 (本次更新主要目的解决此Bug,感谢周珺参与测试)
15	1.4.061211
16		+ 鼠标悬停改变滚动方向 (鼠标悬停控制左右滚动)
17		* 由于文档下载过慢而导致获取的高度/宽度不准确
18		* 浏览器兼容问题 (IE、FF、Opera、NS、MYIE)
19	1.2.060922
20		+ 指定范围间歇滚动
21		* 程序调整
22		* 连续间歇滚动停止的错误
23	1.0.060901
24		+ 向下、向右滚动
25		+ 开始等待时间
26		+ 连续滚动
27		* 调整时间单位
28		* 滚动误差
29		* 随机死循环
30		* 加强性能
31		* 程序优化
32	0.8.060829
33		  翻屏不间断向上、向左滚动
34
35 演示地址:http://www.popub.net/script/MSClass.html
36 下载地址:http://www.popub.net/script/MSClass.js
37
38 应用说明:页面包含<script type="text/javascript" src="MSClass.js"></script>
39	
40	创建实例:
41		//参数直接赋值法
42		new Marquee("marquee")
43		new Marquee("marquee","top")
44		......
45		new Marquee("marquee",0,1,760,52)
46		new Marquee("marquee","top",1,760,52,50,5000)
47		......
48		new Marquee("marquee",0,1,760,104,50,5000,3000,52)
49		new Marquee("marquee",null,null,760,104,null,5000,null,-1)
50
51		//参数动态赋值法
52		var marquee1 = new Marquee("marquee")	*此参数必选
53		marquee1.Direction = "top";	或者	marquee1.Direction = 0;
54		marquee1.Step = 1;
55		marquee1.Width = 760;
56		marquee1.Height = 52;
57		marquee1.Timer = 50;
58		marquee1.DelayTime = 5000;
59		marquee1.WaitTime = 3000;
60		marquee1.ScrollStep = 52;
61		marquee1.Start();
62
63	参数说明:
64		ID		"marquee"	容器ID		(必选)
65		Direction	(0)		滚动方向	(可选,默认为0向上滚动) 可设置的值包括:0,1,2,3,"top","bottom","left","right" (0向上 1向下 2向左 3向右)
66		Step		(1)		滚动的步长	(可选,默认值为2,数值越大,滚动越快)
67		Width		(760)		容器可视宽度	(可选,默认值为容器初始设置的宽度)
68		Height		(52)		容器可视高度	(可选,默认值为容器初始设置的高度)
69		Timer		(50)		定时器		(可选,默认值为30,数值越小,滚动的速度越快,1000=1秒,建议不小于20)
70		DelayTime	(5000)		间歇停顿延迟时间(可选,默认为0不停顿,1000=1秒)
71		WaitTime	(3000)		开始时的等待时间(可选,默认或0为不等待,1000=1秒)
72		ScrollStep	(52)		间歇滚动间距	(可选,默认为翻屏宽/高度,该数值与延迟均为0则为鼠标悬停控制,-1禁止鼠标控制)
73 使用建议:
74		1、建议直接赋予容器的显示区域的宽度和高度,如(<div id="marquee" style="width:760px;height:52px;">......</div>)
75		2、建议为容器添加样式overflow = auto,如(<div id="marquee" style="width:760px;height:52px;overflow:auto;">......</div>)
76		3、为了更准确的获取滚动区域的宽度和高度,请尽可能将各滚动单位直接赋予正确宽高度
77		4、对于TABLE标记的横向滚动,需要对TABLE添加样式display = inline,如(<div id="marquee" style="width:760px;height:52px;overflow:auto;"><table style="display:inline">......</table></div>)
78		5、对于翻屏滚动或间歇滚动,要注意各滚动单位间的间距,同时需要对容器的可视高度和可视宽度做好准确的设置,对于各滚动单位间的间距可以通过设置行间距或者单元格的高宽度来进行调整
79		6、对于LI自动换行的问题暂时没有更好的解决办法,建议将其转换成表格(TABLE)的形式来达到同等的效果
80		7、针对横向滚动的文字段落,如果最末端是以空格" "结束的,请将空格" "转换成"&nbsp;"
81		8、鼠标悬停滚动思想源自Flash,所以有一定的局限性(
81容器内仅允许用图片<img>或者带链接的图片<a><img></a>的形式,并需要禁止其自动换行)
82
83 感  谢:
84	周珺 zhoujun#yuchengtech.com (文字滚动跳行的bug) 2007/01/31
85	自本程序发布以来,收到不少朋友的邮件,提出了很多意见和建议,感谢大家的支持!
86
87\***程序制作/版权所有:崔永祥(333) E-Mail:[email protected] 网址:http://www.popub.net***/
88
89
90function Marquee()
91{
92	this.ID = document.getElementById(arguments[0]);
93	if(!this.ID)
94	{
95		alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
96		this.ID = -1;
97		return;
98	}
99	this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.Correct = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
100	this.Step = 1;
101	this.Timer = 30;
102	this.DirectionArray = {"top":0 , "bottom":1 , "left":2 , "right":3};
103	if(typeof arguments[1] == "number" || typeof arguments[1] == "string")this.Direction = arguments[1];
104	if(typeof arguments[2] == "number")this.Step = arguments[2];
105	if(typeof arguments[3] == "number")this.Width = arguments[3];
106	if(typeof arguments[4] == "number")this.Height = arguments[4];
107	if(typeof arguments[5] == "number")this.Timer = arguments[5];
108	if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
109	if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
110	if(typeof arguments[8] == "number")this.ScrollStep = arguments[8]
111	this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
112	this.ID.noWrap = true;
113	this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
114	if(arguments.length >= 7)this.Start();
115}
116
117
118Marquee.prototype.Start = function()
119{
120	if(this.ID == -1)return;
121	if(this.WaitTime < 800)this.WaitTime = 800;
122	if(this.Timer < 20)this.Timer = 20;
123	if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
124	if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
125	if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
126	this.HalfWidth = Math.round(this.Width / 2);
127	this.HalfHeight = Math.round(this.Height / 2);
128	this.BakStep = this.Step;
129	this.ID.style.width = this.Width + "px";
130	this.ID.style.height = this.Height + "px";
131	if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
132	var msobj = this;
133	var timer = this.Timer;
134	var delaytime = this.DelayTime;
135	var waittime = this.WaitTime;
136	msobj.StartID = function(){msobj.Scroll()}
137	msobj.Continue = function()
138				{
139					if(msobj.MouseOver == 1)
140					{
141						setTimeout(msobj.Continue,delaytime);
142					}
143					else
144					{	clearInterval(msobj.TimerID);
145						msobj.CTL = msobj.Stop = 0;
146						msobj.TimerID = setInterval(msobj.StartID,timer);
147					}
148				}
149
150	msobj.Pause = function()
151			{
152				msobj.Stop = 1;
153				clearInterval(msobj.TimerID);
154				setTimeout(msobj.Continue,delaytime);
155			}
156
157	msobj.Begin = function()
158		{
159			msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth : msobj.ID.scrollHeight;
160			if((msobj.Direction <= 1 && msobj.ClientScroll <= msobj.Height + msobj.Step) || (msobj.Direction > 1 && msobj.ClientScroll <= msobj.Width + msobj.Step))return;
161			msobj.ID.innerHTML += msobj.ID.innerHTML;
162			msobj.TimerID = setInterval(msobj.StartID,timer);
163			if(msobj.ScrollStep < 0)return;
164			msobj.ID.onmousemove = function(event)
165						{
166							if(msobj.ScrollStep == 0 && msobj.Direction > 1)
167							{
168								var event = event || window.event;
169								if(window.event)
170								{
171									if(msobj.IsNotOpera)
172									{
173										msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
174									}
175									else
176									{
177										msobj.ScrollStep = null;
178										return;
179									}
180								}
181								else
182								{
183									msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;
184								}
185								msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
186								msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
187								msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
188							}
189						}
190			msobj.ID.onmouseover = function()
191						{
192							if(msobj.ScrollStep == 0)return;
193							msobj.MouseOver = 1;
194							clearInterval(msobj.TimerID);
195						}
196			msobj.ID.onmouseout = function()
197						{
198							if(msobj.ScrollStep == 0)
199							{
200								if(msobj.Step == 0)msobj.Step = 1;
201								return;
202							}
203							msobj.MouseOver = 0;
204							if(msobj.Stop == 0)
205							{
206								clearInterval(msobj.TimerID);
207								msobj.TimerID = setInterval(msobj.StartID,timer);
208							}
209						}
210		}
211	setTimeout(msobj.Begin,waittime);
212}
213
214Marquee.prototype.Scroll = function()
215{
216	switch(this.Direction)
217	{
218		case 0:
219			this.CTL += this.Step;
220			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
221			{
222				this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
223				this.Pause();
224				return;
225			}
226			else
227			{
228				if(this.ID.scrollTop >= this.ClientScroll)
229				{
230					this.ID.scrollTop -= this.ClientScroll;
231				}
232				this.ID.scrollTop += this.Step;
233			}
234		break;
235
236		case 1:
237			this.CTL += this.Step;
238			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
239			{
240				this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
241				this.Pause();
242				return;
243			}
244			else
245			{
246				if(this.ID.scrollTop <= 0)
247				{
248					this.ID.scrollTop += this.ClientScroll;
249				}
250				this.ID.scrollTop -= this.Step;
251			}
252		break;
253
254		case 2:
255			this.CTL += this.Step;
256			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
257			{
258				this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
259				this.Pause();
260				return;
261			}
262			else
263			{
264				if(this.ID.scrollLeft >= this.ClientScroll)
265				{
266					this.ID.scrollLeft -= this.ClientScroll;
267				}
268				this.ID.scrollLeft += this.Step;
269			}
270		break;
271
272		case 3:
273			this.CTL += this.Step;
274			if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
275			{
276				this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
277				this.Pause();
278				return;
279			}
280			else
281			{
282				if(this.ID.scrollLeft <= 0)
283				{
284					this.ID.scrollLeft += this.ClientScroll;
285				}
286				this.ID.scrollLeft -= this.Step;
287			}
288		break;
289	}
290}
291//-->

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.