用HTML如何实现文字滚动?

html-css010

用HTML如何实现文字滚动?,第1张

\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a

滚动文字\x0d\x0a

滚动文字\x0d\x0a

滚动文字\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0a\x0d\x0amarquee 参数:\x0d\x0aBGColor:滚动文本框的背景颜色。\x0d\x0aDirection:滚动方向设置,可选择Left、Right、up和down。\x0d\x0ascrolldelay:每轮滚动之间的延迟时间,越大越慢。\x0d\x0ascrollamount:一次滚动总的时间量,数字越小滚动越慢。\x0d\x0aBehaviour:滚动的方式设置,三种取值:Scroll(循环滚动) lide(单次滚动)、Alternate(来回滚动)。\x0d\x0aAlign:文字的对齐方式设置。可选择Middle(居中)、Bottom(居下)还是Top(居上)。\x0d\x0aWidth:滚动文本框的宽度,输入一个数值后从后面的单选框选择in Pixels(按像素)或是in Percent(按百分比)。\x0d\x0aHeight:滚动文本框的高度,输入一个数值后从后面的单选框选择in Pixels(按像素)或是in Percent(按百分比)。\x0d\x0aloop:滚动次数。默认为infinite\x0d\x0ahspace、vspace:前后、上下的空行。

回答于 2022-11-16

<!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>