html marquee js怎么监听

JavaScript016

html marquee js怎么监听,第1张

1.滚动方向direction(包括4个值:up、 down、 left和 right)

语法:<marquee direction="滚动方向">...</marquee>

2.滚动方式behavior(scroll:循环滚动,默认效果; slide:只滚动一次就停止; alternate:来回交替进行滚动)

语法:<marquee behavior="滚动方式">...</marquee>

3.滚动速度scrollamount(滚动速度是设置每次滚动时移动的长度,以像素为单位)

语法:<marquee scrollamount="5">...</marquee>

4.滚动延迟scrolldelay(设置滚动的时间间隔,单位是毫秒)

语法:<marquee scrolldelay="100">...</marquee>

5.滚动循环loop(默认值是-1,滚动会不断的循环下去)

语法:<marquee loop="2">...</marquee>

6.滚动范围width、height

7.滚动背景颜色bgcolor

8.空白空间hspace、vspace

js是达到无缝滚动的效果

marquee的效果却不同,必须要前一次滚动完成之后,才会接着下一次!

两次之间留下一段空白!

没有什么费事不费事的问题,只是看你自己需要什么效果而已!

使用方法:

使用该跑马灯特效之前要先引入jQuery和marquee.js文件。

<script src="jquery-1.11.2.min.js"></script><script src="marquee.js"></script>

HTML结构:

跑马灯中的文字使用无序列表来制作,外面使用一个<div>作为包裹容器。

123456789101112    <div class="container">  <div class="marquee-sibling"> Breaking News </div>  <div class="marquee">    <ul class="marquee-content-items">      <li>Item 1</li>      <li>Item 2</li>      <li>Item 3</li>      <li>Item 4</li>      <li>Item 5</li>    </ul>  </div></div> 

CSS样式:

下面是该跑马灯特效的一些基本样式。

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354    .container {  width: 100%  background: #4FC2E5  float: left  display: inline-block  overflow: hidden  box-sizing: border-box  height: 45px  position: relative  cursor: pointer}  .marquee-sibling {  padding: 0  background: #3BB0D6  width: 20%  height: 45px  line-height: 42px  font-size: 12px  font-weight: normal  color: #ffffff  text-align: center  float: left  left: 0  z-index: 2000}  .marquee,*[class^="marquee"] {  display: inline-block  white-space: nowrap  position: absolute}  .marquee { margin-left: 25% }  .marquee-content-items {  display: inline-block  padding: 5px  margin: 0  height: 45px  position: relative}  .marquee-content-items li {  display: inline-block  line-height: 35px  color: #fff}  .marquee-content-items li:after {  content: "|"  margin: 0 1em}  

初始化插件:

123    $(function (){  createMarquee()}) 

在页面加载完毕之后,可以通过下面的方法来初始化该跑马灯插件。

配置参数:

下面是该跑马灯特效的可用配置参数。

12345678910111213141516171819202122232425262728    $(function (){    createMarquee({          // controls the speed at which the marquee moves    duration:30000,       // right margin between consecutive marquees    padding:20,       // class of the actual div or span that will be used to create the marquee -     // multiple marquee items may be created using this item's content.     // This item will be removed from the dom    marquee_class:'.example-marquee',       // the container div in which the marquee content will animate.     container_class: '.example-container',       // a sibling item to the marqueed item  that affects -     // the end point position and available space inside the container.     sibling_class: '.example-sibling',       // Boolean to indicate whether pause on hover should is required.     hover: false    })  })