博主最近在写一个比较简单的网页,想要实现滚动字幕的效果,从网上也查了一些资料,有一些是利用JS实现的,效果有好有坏但都比较复杂。偶然间看到了marquee标签,发现使用marquee标签实现这个效果很简单效果也不错。
marquee介绍
<marquee>hello world</marquee>
常用两个事件
onMouseOut=”this.start()” 鼠标移除该区域开始移动
onMouseOver=”this.stop()” 鼠标移到该区域停止移动
<marquee> onMouseOut="this.start()" onMouseOver="this.stop()">常用的两个事件</marquee>
* 属性*
behavior设定滚动的方式:
alternate:来回滚动
scroll:重复滚动
slide:不重复滚动
<marquee behavior="alternate">来回滚动。 </marquee>
<marquee behavior="scroll">重复滚动。</marquee>
<marquee behavior="slide">不重复滚动。</marquee>
活动字幕背景颜色
使用bgcolor背景颜色:
有三种方式
<marquee bgcolor="#006699">设定活动字幕的背景颜色</marquee>
<marquee bgcolor="RGB(10%,50%,100%,)">设定活动字幕的背景颜色 </marquee>
<marquee bgcolor="red">设定活动字幕的背景颜色</marquee>
设置字幕的滚动方向
使用direction:
<marquee direction="down">设定活动字幕的滚动方向向下</marquee>
<marquee direction="left">设定活动字幕的滚动方向向左</marquee>
<marquee direction="right">设定活动字幕的滚动方向向右</marquee>
<marquee direction="up">设定活动字幕的滚动方向向上</marquee>
设置宽度与高度
使用height设置高度,width设置宽度:
<marquee height="500" direction="down" bgcolor="#CCCCCC">设定活动字幕的高度</marquee>
<marquee width="500" bgcolor="#CCCCCC">设定活动字幕的宽度</marquee>
设置滚动次数与速度
loop设定滚动次数:
loop==-1表示一直滚动下去,默认为-1
<marquee loop="-1" bgcolor="#CCCCCC">我会不停地走。</marquee>
<marquee loop="2" bgcolor="#CCCCCC">我只走两次哦</marquee>
scrollamount设定滚动速度:单位pix
<marquee scrollamount="10" >scrollamount="10" </marquee>
<marquee scrollamount="20" >scrollamount="20" </marquee>
<marquee scrollamount="30" >scrollamount="30" </marquee>
scrolldelay设置滚动两次的延迟时间,单位为毫秒
<marquee scrolldelay="10" >scrolldelay="10" </marquee>
<marquee scrolldelay="100" > scrolldelay="100"</marquee>
<marquee scrolldelay="1000">scrolldelay="1000" </marquee>
关于图片
marquee也可以使图片滚动
<marquee>
<img border=0 src="...jpg" >
</marquee>
实例
<marquee behavior="scroll" direction=left height=82 width=500 scrollamount=10 scrolldelay=9 width="100%" bgcolor="white">
<img border=0 src="images/hemei_02.jpg" >
</marquee>
赶快自己试试效果吧!