解决JS文字滚动

JavaScript0135

解决JS文字滚动,第1张

代码帮你改了,希望对你有帮助

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">

<title>连续滚动示例</title>

</head>

<body>

<script>

var fn = new Object()

fn.param = "要带的参数"

fn.initScrolling = function(){

alert(fn.param)

scrollingBox = document.getElementById('xst')

scrollingBox.style.overflow = "hidden"

scrollingInterval = setInterval("scrolling()",50)

scrollingBox.onmouseover = over

scrollingBox.onmouseout = out

}

function addEventSimple(obj,evt,fn){

if(obj.addEventListener){

obj.addEventListener(evt,fn,false)

}else if(obj.attachEvent){

obj.attachEvent('on'+evt,fn)

}

}

addEventSimple(window,'load',fn.initScrolling)

var scrollingBox

var scrollingInterval

var reachedBottom=false

var bottom

function scrolling(){

var origin = scrollingBox.scrollTop++

if(origin == scrollingBox.scrollTop){

if(!reachedBottom){

scrollingBox.innerHTML+=scrollingBox.innerHTML

reachedBottom=true

bottom=origin

}else{

scrollingBox.scrollTop=bottom

}

}

}

function over(){

clearInterval(scrollingInterval)

}

function out(){

scrollingInterval = setInterval("scrolling()",50)

}

</script>

<div id="xst" style="width:289pxheight:163px">

<p>第一行</p>

<p>第二行</p>

<p>第三行</p>

</div>

<input type="button" value="测试" onclick="fn.initScrolling()"/>

</body>

</html>

<marquee onMouseOver=this.stop() 

onMouseOut=this.start() scrollamount=1 

scrolldelay=7 direction=up width=270 

height=77> 滚动的文字 

</marquee>