文本特效-jQuery简单的文字跑马灯特效

这是一款非常简单的jQuery文字跑马灯特效插件。该跑马灯特效使文本从右向左不停循环,当鼠标放到跑马灯上的文字时,跑马灯会暂停运动。

使用方法

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

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

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

<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样式

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

.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;
}
         
初始化插件

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

$(function (){
  createMarquee();
});
               

配置参数

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

$(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
  });
});
               

在线预览 网盘下载

郑重声明:

1 本资源来源于互联网,资源的版权归资源原作者所持有,受《中华人民共和国著作权法》等相关法律保护。

2 由于无法和原作者取得联系,所以上传的部分资源无法先通过原作者的同意就分享给大家了,如本资源侵犯了您(原作者)的权益,请联系我们(微信号 xiaohaimei1989),我们会立马删除您的资源,并向您表达诚挚的歉意!

3 本站是一个公益型网站,分享资源的目的在于传播知识,分享知识,收取一点点打赏的辛苦费是用于网站的日常运营开支,并非用于商业用途。

4 本站资源只提供学习和参考研究使用,使用过后请在第一时间内删除。本站不承担资源被单位或个人商用带来的法律责任。

发表评论