HTML滚动公告,隔3秒向上滚动显示下一条文字的代码是什么?

html-css08

HTML滚动公告,隔3秒向上滚动显示下一条文字的代码是什么?,第1张

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

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

<title></title>

<script type="text/javascript">

var RollAd=(function() {

var _extend=function(desitination,source) {

for (var m in source) {

desitination[m]=source[m]

}

return desitination

}

var constructor=function(

container, /*需要绑定的marquee容器,可以传id,也可以也直接传dom 元素*/

freq, /*滚动的时间,单位秒*/

delay, /*两次滚动的间隔时间,单位秒*/

style /*marquee元素的样式*/

) {

var self=this

var stoped=false

var rollTimeoutId=null

container=(typeof container=='string'?document.getElementById(container):container)

style=_extend({

width:'100%',

height:'15px' 

},style || {}) 

for (var s in style) {

container.style.s=style[s]

}

var _roll=function() {

if (!stoped) {

rollTimeoutId=setTimeout(_stop,freq*1000)

} else {

rollTimeoutId=setTimeout(_start,delay*1000)

}

}

var _start=function() {

stoped=false

container.start()

_roll()

}

var _stop=function() {

stoped=true

container.stop()

_roll()

}

_roll()

}

return constructor 

})()

/*示例代码*/

window.onload=function() {

new RollAd('rollAd',3,4)

}

</script>

</head>

<body>

<marquee direction="up" behavior="scroll" scrollamount="1" scrolldelay="15" id="rollAd">

dfdfasfdsa <br />

dfdfd<br />

dfdfdf<br />

dfdfdf<br />

</marquee>

</body>

</html>

用编缉类软件打开公告所在网页,把滚动公告的HTML代码粘贴在你需要的位置。然后保存并用FTP软件上传到空间。再次打开网页就会看到滚动公告的。

语法:<marquee>…</marquee>

使用移动属性marquee,不仅仅可以舞动你的文字,还可以应用于图片,表格等等。

例:<marquee direction=left>欢迎光临梦泽科技网站!</marquee>

direction=left,表示方向。上面文字效果是“欢迎光临梦泽科技网站!”从右向左移动!另外,方向还有right,up,down。

除了方向,我们还可以添加其他限制的元素:

移动的方式:

循环移动:loop=n(n,表示次数) 绕圈移动:behavior=scroll 只走一次:behavior=slide 来回移动:behavior=alternate

外观:

字号:<font size=n>(n,变量) 对齐方式:align=top/middle/bottom 底色:bgcolor=Blue(预定义色彩,如:Black,Olive,Teal,Red,Blue,Maroon, Navy,Gray,Lime,Fuchsia,White,Green,Purple,Silver,Yellow,Aqua或16进制数码)

其它:

 速度:scrollamount=n(n,变量) 延时:scrolldelay==n(n,变量)

<marquee direction="向什么方向移动" height="移动区域高度" width="移动区域宽度" scrollamount="移动速度" onmouseover=this.stop() onmouseout=this.start()>"

onmouseover 设置鼠标放在移动区域的时候暂停移动

onmouseout 鼠标离开的时候继续滚动

使用 marquee标签

这里是个简单的滚动小例子,这个标签还有很多好用的属性,可以自己查一查

<html>

<body>

<marquee direction='up' scrollamount="3" loop="infinite">

<a>fadsfasdf</a></br>

<a>fadsfasdf</a></br>

<a>fadsfasdf</a>

</marquee>

</body>

</html>