这个js文件引用之后,如何去实现其功能呢?

叫我梁大侠 2010-07-20 08:06:48
我这找到了个无间隙滚动的JS代码,可是却不知道怎么却使用,我小菜一个,不懂JS,望高人指点下。
MSClass.js代码如下:
function Marquee()
{
this.ID = document.getElementById(arguments[0]);
if(!this.ID)
{
alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
this.ID = -1;
return;
}
this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
this.Step = 1;
this.Timer = 30;
this.DirectionArray = {"top":0 , "up":0 , "bottom":1 , "down":1 , "left":2 , "right":3};
if(typeof arguments[1] == "number" || typeof arguments[1] == "string")this.Direction = arguments[1];
if(typeof arguments[2] == "number")this.Step = arguments[2];
if(typeof arguments[3] == "number")this.Width = arguments[3];
if(typeof arguments[4] == "number")this.Height = arguments[4];
if(typeof arguments[5] == "number")this.Timer = arguments[5];
if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
if(typeof arguments[8] == "number")this.ScrollStep = arguments[8];
this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
this.ID.noWrap = true;
this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
if(arguments.length >= 7)this.Start();
}

Marquee.prototype.Start = function()
{
if(this.ID == -1)return;
if(this.WaitTime < 800)this.WaitTime = 800;
if(this.Timer < 20)this.Timer = 20;
if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
this.HalfWidth = Math.round(this.Width / 2);
this.HalfHeight = Math.round(this.Height / 2);
this.BakStep = this.Step;
this.ID.style.width = this.Width + "px";
this.ID.style.height = this.Height + "px";
if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td></tr></table>";
var templateTop = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;'><tr><td>MSCLASS_TEMP_HTML</td></tr><tr><td>MSCLASS_TEMP_HTML</td></tr></table>";
var msobj = this;
msobj.tempHTML = msobj.ID.innerHTML;
if(msobj.Direction <= 1)
{
msobj.ID.innerHTML = templateTop.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);
}
else
{
if(msobj.ScrollStep == 0 && msobj.DelayTime == 0)
{
msobj.ID.innerHTML += msobj.ID.innerHTML;
}
else
{
msobj.ID.innerHTML = templateLeft.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);
}
}
var timer = this.Timer;
var delaytime = this.DelayTime;
var waittime = this.WaitTime;
msobj.StartID = function(){msobj.Scroll()}
msobj.Continue = function()
{
if(msobj.MouseOver == 1)
{
setTimeout(msobj.Continue,delaytime);
}
else
{ clearInterval(msobj.TimerID);
msobj.CTL = msobj.Stop = 0;
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}

msobj.Pause = function()
{
msobj.Stop = 1;
clearInterval(msobj.TimerID);
setTimeout(msobj.Continue,delaytime);
}

msobj.Begin = function()
{
msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth / 2 : msobj.ID.scrollHeight / 2;
if((msobj.Direction <= 1 && msobj.ClientScroll <= msobj.Height + msobj.Step) || (msobj.Direction > 1 && msobj.ClientScroll <= msobj.Width + msobj.Step)) {
msobj.ID.innerHTML = msobj.tempHTML;
delete(msobj.tempHTML);
return;
}
delete(msobj.tempHTML);
msobj.TimerID = setInterval(msobj.StartID,timer);
if(msobj.ScrollStep < 0)return;
msobj.ID.onmousemove = function(event)
{
if(msobj.ScrollStep == 0 && msobj.Direction > 1)
{
var event = event || window.event;
if(window.event)
{
if(msobj.IsNotOpera)
{
msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
}
else
{
msobj.ScrollStep = null;
return;
}
}
else
{
msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;
}
msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
}
}
msobj.ID.onmouseover = function()
{
if(msobj.ScrollStep == 0)return;
msobj.MouseOver = 1;
clearInterval(msobj.TimerID);
}
msobj.ID.onmouseout = function()
{
if(msobj.ScrollStep == 0)
{
if(msobj.Step == 0)msobj.Step = 1;
return;
}
msobj.MouseOver = 0;
if(msobj.Stop == 0)
{
clearInterval(msobj.TimerID);
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}
}
setTimeout(msobj.Begin,waittime);
}

Marquee.prototype.Scroll = function()
{
switch(this.Direction)
{
case 0:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop >= this.ClientScroll)
{
this.ID.scrollTop -= this.ClientScroll;
}
this.ID.scrollTop += this.Step;
}
break;

case 1:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop <= 0)
{
this.ID.scrollTop += this.ClientScroll;
}
this.ID.scrollTop -= this.Step;
}
break;

case 2:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft >= this.ClientScroll)
{
this.ID.scrollLeft -= this.ClientScroll;
}
this.ID.scrollLeft += this.Step;
}
break;

case 3:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft <= 0)
{
this.ID.scrollLeft += this.ClientScroll;
}
this.ID.scrollLeft -= this.Step;
}
break;
}
}
我在要滚动的页面中加入了引用代码并且创建了实例:
<script src="MSClass.js" type="text/javascript">
var marquee1 = new Marquee("marquee")
marquee1.Direction = "top";
marquee1.Step = 1;
marquee1.Width = 400;
marquee1.Height = 200;
marquee1.Timer = 50;
marquee1.DelayTime = 5000;
marquee1.WaitTime = 3000;
marquee1.ScrollStep = 52;
marquee1.Start();
</script>
我自己想的就是通过<div>来实现里面文字的内容,可是这里如何去写呢?
我自己写的是<div id="marquee1" style="overflow:auto;">测试测试</div>
调试却发现不滚动,望高人指点下,我小菜一个,谢谢。
...全文
84 点赞 收藏 18
写回复
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
<div id="themarquee">aaaaa<p>bbbb<p>ccccc<p>ddddd<p>eeee<p>1111<p>ccccc<p>222<p>3333<p></div>

<script type="text/javascript">
function Marquee() {
this.ID = document.getElementById(arguments[0]);
if (!this.ID) {
alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
this.ID = -1;
return;
}
this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
this.Step = 1;
this.Timer = 30;
this.DirectionArray = {
"top": 0,
"up": 0,
"bottom": 1,
"down": 1,
"left": 2,
"right": 3
};
if (typeof arguments[1] == "number" || typeof arguments[1] == "string") this.Direction = arguments[1];
if (typeof arguments[2] == "number") this.Step = arguments[2];
if (typeof arguments[3] == "number") this.Width = arguments[3];
if (typeof arguments[4] == "number") this.Height = arguments[4];
if (typeof arguments[5] == "number") this.Timer = arguments[5];
if (typeof arguments[6] == "number") this.DelayTime = arguments[6];
if (typeof arguments[7] == "number") this.WaitTime = arguments[7];
if (typeof arguments[8] == "number") this.ScrollStep = arguments[8];
this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
this.ID.noWrap = true;
this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
if (arguments.length >= 7) this.Start();
}

Marquee.prototype.Start = function() {
if (this.ID == -1) return;
if (this.WaitTime < 800) this.WaitTime = 800;
if (this.Timer < 20) this.Timer = 20;
if (this.Width == 0) this.Width = parseInt(this.ID.style.width);
if (this.Height == 0) this.Height = parseInt(this.ID.style.height);
if (typeof this.Direction == "string") this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
this.HalfWidth = Math.round(this.Width / 2);
this.HalfHeight = Math.round(this.Height / 2);
this.BakStep = this.Step;
this.ID.style.width = this.Width + "px";
this.ID.style.height = this.Height + "px";
if (typeof this.ScrollStep != "number") this.ScrollStep = this.Direction > 1 ? this.Width: this.Height;
var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td></tr></table>";
var templateTop = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;'><tr><td>MSCLASS_TEMP_HTML</td></tr><tr><td>MSCLASS_TEMP_HTML</td></tr></table>";
var msobj = this;
msobj.tempHTML = msobj.ID.innerHTML;
if (msobj.Direction <= 1) {
msobj.ID.innerHTML = templateTop.replace(/MSCLASS_TEMP_HTML/g, msobj.ID.innerHTML);
} else {
if (msobj.ScrollStep == 0 && msobj.DelayTime == 0) {
msobj.ID.innerHTML += msobj.ID.innerHTML;
} else {
msobj.ID.innerHTML = templateLeft.replace(/MSCLASS_TEMP_HTML/g, msobj.ID.innerHTML);
}
}
var timer = this.Timer;
var delaytime = this.DelayTime;
var waittime = this.WaitTime;
msobj.StartID = function() {
msobj.Scroll()
}
msobj.Continue = function() {
if (msobj.MouseOver == 1) {
setTimeout(msobj.Continue, delaytime);
} else {
clearInterval(msobj.TimerID);
msobj.CTL = msobj.Stop = 0;
msobj.TimerID = setInterval(msobj.StartID, timer);
}
}

msobj.Pause = function() {
msobj.Stop = 1;
clearInterval(msobj.TimerID);
setTimeout(msobj.Continue, delaytime);
}

msobj.Begin = function() {
msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth / 2 : msobj.ID.scrollHeight / 2;
if ((msobj.Direction <= 1 && msobj.ClientScroll <= msobj.Height + msobj.Step) || (msobj.Direction > 1 && msobj.ClientScroll <= msobj.Width + msobj.Step)) {
msobj.ID.innerHTML = msobj.tempHTML;
delete(msobj.tempHTML);
return;
}
delete(msobj.tempHTML);
msobj.TimerID = setInterval(msobj.StartID, timer);
if (msobj.ScrollStep < 0) return;
msobj.ID.onmousemove = function(event) {
if (msobj.ScrollStep == 0 && msobj.Direction > 1) {
var event = event || window.event;
if (window.event) {
if (msobj.IsNotOpera) {
msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft: event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
} else {
msobj.ScrollStep = null;
return;
}
} else {
msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;
}
msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep * 2) / msobj.HalfWidth);
}
}
msobj.ID.onmouseover = function() {
if (msobj.ScrollStep == 0) return;
msobj.MouseOver = 1;
clearInterval(msobj.TimerID);
}
msobj.ID.onmouseout = function() {
if (msobj.ScrollStep == 0) {
if (msobj.Step == 0) msobj.Step = 1;
return;
}
msobj.MouseOver = 0;
if (msobj.Stop == 0) {
clearInterval(msobj.TimerID);
msobj.TimerID = setInterval(msobj.StartID, timer);
}
}
}
setTimeout(msobj.Begin, waittime);
}

Marquee.prototype.Scroll = function() {
switch (this.Direction) {
case 0:
this.CTL += this.Step;
if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
} else {
if (this.ID.scrollTop >= this.ClientScroll) {
this.ID.scrollTop -= this.ClientScroll;
}
this.ID.scrollTop += this.Step;
}
break;

case 1:
this.CTL += this.Step;
if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
} else {
if (this.ID.scrollTop <= 0) {
this.ID.scrollTop += this.ClientScroll;
}
this.ID.scrollTop -= this.Step;
}
break;

case 2:
this.CTL += this.Step;
if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
} else {
if (this.ID.scrollLeft >= this.ClientScroll) {
this.ID.scrollLeft -= this.ClientScroll;
}
this.ID.scrollLeft += this.Step;
}
break;

case 3:
this.CTL += this.Step;
if (this.CTL >= this.ScrollStep && this.DelayTime > 0) {
this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
} else {
if (this.ID.scrollLeft <= 0) {
this.ID.scrollLeft += this.ClientScroll;
}
this.ID.scrollLeft -= this.Step;
}
break;
}
}

var marquee1 = new Marquee("themarquee")
marquee1.Direction = "up";
marquee1.Step = 2;
marquee1.Width = 100;
marquee1.Height = 150;
marquee1.Timer = 50;
marquee1.DelayTime = 0;
marquee1.WaitTime = 0;
marquee1.ScrollStep = 2;
marquee1.Start();
</script>
回复
APM60- 2010-07-22
[Quote=引用 12 楼 lzp4881 的回复:]
有些东西搜索一下就有了,不要什么都问
[/Quote]
上下滚动的话,内容高度要大于容器高度。

把这句
this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
改为
this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "scroll";
显示滚动条
多改几个高度值,看能看明白原因不。

回复
叫我梁大侠 2010-07-22
在顶下,大哥帮帮忙哦。
回复
叫我梁大侠 2010-07-22
额 我先去试下
回复
lzp4881 2010-07-21
有些东西搜索一下就有了,不要什么都问
回复
lzp4881 2010-07-21
new Marquee(

"scroll", //容器ID<br />
0, //向上滚动(0向上 1向下 2向左 3向右)<br />
2, //滚动的步长<br />
248, //容器可视宽度<br />
370, //容器可视高度<br />
50, //定时器 数值越小,滚动的速度越快(1000=1秒,建议不小于20)<br />
1000, //间歇停顿时间(0为不停顿,1000=1秒)<br />
1000, //开始时的等待时间(0为不等待,1000=1秒)<br />
160//间歇滚动间距(可选)<br />
);
回复
叫我梁大侠 2010-07-21
大哥哥 貌似它滚动一会就会停下来饿 怎么设置无线滚动呢 是第五个参数么?那个Timer?
谢谢
回复
叫我梁大侠 2010-07-21
恩 谢谢大哥
回复
lzp4881 2010-07-21
new Marquee("marqueediv6",2,1,760,52,20,0,0)
红色的是速度,数字越大越慢。
回复
叫我梁大侠 2010-07-21
饿 那个速度怎么设置饿?
回复
马老虎 2010-07-21
但愿能接上分!
恭喜下!
回复
叫我梁大侠 2010-07-21
我刚改了下那些参数,现在好了,谢谢大哥哥。
回复
叫我梁大侠 2010-07-21
谢谢大哥,可是我要的是文字无间隙向上滚动的哦。
我把你的代码那些图片链接的改成文字后就不滚动了饿。
大哥指点下,谢谢。
回复
lzp4881 2010-07-21
<html>
<head></head>
<body>
<script>
function Marquee()
{
this.ID = document.getElementById(arguments[0]);
this.Direction = arguments[1];
this.Step = arguments[2];
this.Width = arguments[3];
this.Height = arguments[4];
this.Timer = arguments[5];
this.WaitTime = arguments[6];
this.StopTime = arguments[7];
if(arguments[8])
this.ScrollStep = arguments[8]
else
this.ScrollStep = this.Direction>1 ? this.Width : this.Height;
this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
this.ID.noWrap = true;
this.ID.style.width = this.Width;
this.ID.style.height = this.Height;
this.ClientScroll = this.Direction>1 ? this.ID.scrollWidth : this.ID.scrollHeight;
this.ID.innerHTML += this.ID.innerHTML;
this.Start(this,this.Timer,this.WaitTime,this.StopTime);
}

Marquee.prototype.Start = function(msobj,timer,waittime,stoptime)
{
msobj.StartID = function(){msobj.Scroll()}
msobj.Continue = function()
{
if(msobj.MouseOver == 1)
{
setTimeout(msobj.Continue,waittime);
}
else
{ clearInterval(msobj.TimerID);
msobj.CTL = msobj.Stop = 0;
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}
msobj.Pause = function()
{
msobj.Stop = 1;
clearInterval(msobj.TimerID);
setTimeout(msobj.Continue,waittime);
}
msobj.Begin = function()
{
msobj.TimerID = setInterval(msobj.StartID,timer);
msobj.ID.onmouseover = function()
{
msobj.MouseOver = 1;
clearInterval(msobj.TimerID);
}
msobj.ID.onmouseout = function()
{
msobj.MouseOver = 0;
if(msobj.Stop == 0)
{
clearInterval(msobj.TimerID);
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}
}
setTimeout(msobj.Begin,stoptime);
}
Marquee.prototype.Scroll = function()
{
switch(this.Direction)
{
case 0:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep & this.WaitTime > 0)
{
this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop >= this.ClientScroll)
{
this.ID.scrollTop -= this.ClientScroll;
}
this.ID.scrollTop += this.Step;
}
break;
case 1:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep & this.WaitTime > 0)
{
this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop <= 0)
{
this.ID.scrollTop += this.ClientScroll;
}
this.ID.scrollTop -= this.Step;
}
break;
case 2:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep & this.WaitTime > 0)
{
this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft >= this.ClientScroll)
{
this.ID.scrollLeft -= this.ClientScroll;
}
this.ID.scrollLeft += this.Step;
}
break;
case 3:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep & this.WaitTime > 0)
{
this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft <= 0)
{
this.ID.scrollLeft += this.ClientScroll;
}
this.ID.scrollLeft -= this.Step;
}
break;
}
}
-->
</script>

<DIV id=marqueediv6><IMG height=50 hspace=1 src="a.jpg" width=150
border=0><IMG height=50 hspace=1 src="b.jpg" width=150
border=0><IMG height=50 hspace=1 src="c.jpg" width=150
border=0><IMG height=50 hspace=1 src="d.jpg" width=150
border=0><IMG height=50 hspace=1 src="b.jpg" width=150
border=0><IMG height=50 hspace=1 src="b.jpg" width=150
border=0></DIV>
<script>
new Marquee("marqueediv6",2,1,760,52,20,0,0)
</script>

</body>
</html>
回复
叫我梁大侠 2010-07-21
自己再顶下
回复
叫我梁大侠 2010-07-21
大哥哥,我的意思是 我实现了怎么去滚动,那些参数我都调了,可是滚动一会后就不滚动了额
再指点下,谢谢。
回复
叫我梁大侠 2010-07-21

谢谢大哥
回复
叫我梁大侠 2010-07-20
自己帮自己顶下
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告