请问如何做一个滚动字幕?

artak 2008-12-03 02:58:04
请问如何做一个滚动字幕?不要marque,因为用marque的时候,进入页面或者刷新页面,总是空白,然后字幕才慢慢滚出来的
要求进去,就是一屏字幕,然后才滚,而不是空白,在滚出来
...全文
240 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zengxiongbin 2008-12-03
  • 打赏
  • 举报
回复
<div id="info" style="overflow:hidden; height:300px;">
<div id="b1">
<ul><li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
<li>aaaaaaaaaaaa</li>
</ul>
</div>
<div id="bgun"></div>
</div>
<script language="javascript">
var speed=30
bgun.innerHTML=b1.innerHTML
function Marquee(){
if(bgun.offsetTop-info.scrollTop<=0)
info.scrollTop-=b1.offsetHeight
else{
info.scrollTop++
}}
var MyMar=setInterval(Marquee,speed)
info.onmouseover=function() {clearInterval(MyMar)}
info.onmouseout=function() {MyMar=setInterval(Marquee,speed)}</script>
</div>
twin21cn 2008-12-03
  • 打赏
  • 举报
回复
用JS代码控制
jiangzhe556 2008-12-03
  • 打赏
  • 举报
回复
http://download.csdn.net/source/829139

去这里下吧!我都实验过了,都可以用的,无缝滚动向上向下向左向右的代码
DIV实现的
anncesky 2008-12-03
  • 打赏
  • 举报
回复
这可很容易啊,,,星星啊,可能你对JS不怎么了解

就是用一个DIV装入文字,把它的div.style.Left=div.style.Left-1做递归
控制头尾就可以
shine_fly 2008-12-03
  • 打赏
  • 举报
回复
var __scrollBarControl = null;

function innerBarProp(barID, width, height, interval, direction)
{
this.barID = barID;
this.width = width;
this.height = height;
this.interval = interval;
this.direction = direction;
this.stopScroll = false;
this.maxValue = 0;
this.preValue = 0;
}

function scrollBar()
{
this.barsArray = new Array();
//save current object
__scrollBarControl = this;
}

scrollBar.prototype.addBar = function(barID, width, height, interval, direction)
{
//check parameters
var paraCount = arguments.length;
if ( paraCount < 1 )
{
alert("parameters count incorect!");
return;
//throw "parameters count inccorect!";
}

//width's default value
if ( typeof( width ) == "undefined" )
{
var width = 100;
}

//height's default value
if ( typeof( height ) == "undefined" )
{
var height = 100;
}

//interval's default value
if ( typeof( interval ) == "undefined" )
{
var interval = 1000;
}

//direction's default value
if ( typeof( direction ) == "undefined" )
{
var direction = "up";
}

//create scrollbar's inner properties
var barProp = new innerBarProp(barID, width, height, interval, direction);
var barCount = this.barsArray.length;
this.barsArray[barCount] = barProp;
}

scrollBar.prototype.createScrollBars = function()
{
//get bar's count
var barCount = this.barsArray.length;
//if no bar add to scrollControl do nothing
if ( barCount == 0 )
{
return;
}

//init scroll bars
for ( var i=0; i<barCount; i++ )
{
var objBarID = this.barsArray[i].barID;
//if typeof objBarID is object
// that's meaning it inited
//if typeof objBarID is string
// init that scroll bar
if ( typeof( objBarID ) == "string" )
{
//get scroll <DIV> object
var objBar = document.getElementById( objBarID );
if (objBar == null)
{
//objBarID is not exist
if ( document.readyState == "complete" || document.readyState == "loaded" )
{
//the objBarID not exists in current document
//throw "the objBarID is not exists.";
alert("ScrollBar[" + objBarID + "]: not exist!");
return;
}
else
{
//wait for document to load objBarID
window.setTimeout("__scrollBarControl.createScrollBars()",50);
//exit processing..........
//and wait next time callbak
return;
}
}

//update barID
this.barsArray[i].barID = objBar;
}
}

for ( var i=0; i<barCount; i++ )
{
this.innerInitBar(i);
}
}

scrollBar.prototype.innerInitBar = function (index)
{
//get properties
var barID = this.barsArray[index].barID;
var width = this.barsArray[index].width;
var height = this.barsArray[index].height;
var interval = this.barsArray[index].interval;
var direction = this.barsArray[index].direction;
var maxValue = 0;

//set scrollBar's properties
with(barID)
{
style.width = width;
style.height = height;
noWrap=true;

switch( direction )
{
case "up":
maxValue = Math.max(scrollHeight, height);
style.overflowX = "visible";
style.overflowY = "hidden";
var barHtml = innerHTML;
var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
newHtml += " <tr>\n";
newHtml += " <td height='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " </tr>\n";
newHtml += " <tr>\n";
newHtml += " <td height='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " </tr>\n";
newHtml += "</table>\n";
innerHTML = newHtml;
break;
case "down":
maxValue = Math.max(scrollHeight, height);
style.overflowX = "visible";
style.overflowY = "hidden";
var barHtml = innerHTML;
var newHtml = "<table border='0' cellspacing='0' cellpadding='0'>\n";
newHtml += " <tr>\n";
newHtml += " <td height='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " </tr>\n";
newHtml += " <tr>\n";
newHtml += " <td height='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " </tr>\n";
newHtml += "</table>\n";
innerHTML = newHtml;
scrollTop = maxValue;
break;
case "left":
maxValue = Math.max(scrollWidth, width);
style.overflowX = "hidden";
style.overflowY = "visible";
var barHtml = barID.innerHTML;
var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
newHtml += " <tr>\n";
newHtml += " <td width='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " <td width='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " </tr>\n";
newHtml += "</table>\n";
innerHTML = newHtml;
break;
case "right":
maxValue = Math.max(scrollWidth, width);
style.overflowX = "hidden";
style.overflowY = "visible";
var barHtml = innerHTML;
var newHtml = "<table border='0' cellspacing='0' cellpadding='0' width='" + (maxValue * 2 ) + "'>\n";
newHtml += " <tr>\n";
newHtml += " <td width='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " <td width='" + maxValue + "' valign='top'>\n";
newHtml += barHtml + "\n";
newHtml += " </td>\n";
newHtml += " </tr>\n";
newHtml += "</table>\n";
innerHTML = newHtml;
scrollLeft = maxValue;
break;
default:
//throw "direction is inccorect!";
alert("ScrollBar[" + id + "]: direction is incorect!");
return;
}

//set mouse events
onmouseover = new Function("__scrollBarControl.mouseEvt(" + index + ",true);");
onmouseout = new Function("__scrollBarControl.mouseEvt(" + index + ",false);");
window.setInterval("__scrollBarControl.scroll(" + index + ");",interval);

//save maxValue
this.barsArray[index].maxValue = maxValue;
}
}

scrollBar.prototype.mouseEvt = function(index, stop)
{
this.barsArray[index].stopScroll = stop;
}

scrollBar.prototype.scroll = function(index)
{
//get properties
var barID = this.barsArray[index].barID;
var width = this.barsArray[index].width;
var height = this.barsArray[index].height;
var interval = this.barsArray[index].interval;
var direction = this.barsArray[index].direction;
var stopScroll = this.barsArray[index].stopScroll;
var preValue = this.barsArray[index].preValue;
var maxValue = this.barsArray[index].maxValue;

if ( stopScroll == true ) return;

switch(direction)
{
case "up":
preValue++;
if ( preValue >= maxValue )
{
preValue = 0;
}
barID.scrollTop = preValue;
break;
case "down":
preValue--;
if ( preValue <= 0 )
{
preValue = maxValue;
}
barID.scrollTop = preValue;
break;
case "left":
preValue++;
if ( preValue >= maxValue )
{
preValue = 0;
}
barID.scrollLeft = preValue;
break;
case "right":
preValue--;
if ( preValue <=0 )
{
preValue = maxValue;
}
barID.scrollLeft = preValue;
break;
}
this.barsArray[index].preValue = preValue;
}
brio8425 2008-12-03
  • 打赏
  • 举报
回复
滚动的效果似乎baidu里好多很多。。。。。。

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧