文本/链接

jQuery简单文字跑马灯特效

阿里云


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

使用方法:

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

也想出现在这里?联系我们
创客主机
  1. <script src="jquery-1.11.2.min.js"></script>
  2. <script src="marquee.js"></script>

HTML 结构:

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

  1. <div class="container">
  2.   <div class="marquee-sibling"> Breaking News </div>
  3.   <div class="marquee">
  4.     <ul class="marquee-content-items">
  5.       <li>Item 1</li>
  6.       <li>Item 2</li>
  7.       <li>Item 3</li>
  8.       <li>Item 4</li>
  9.       <li>Item 5</li>
  10.     </ul>
  11.   </div>
  12. </div>

CSS 样式:

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

  1. .container {
  2.   width: 100%;
  3.   background: #4FC2E5;
  4.   float: left;
  5.   display: inline-block;
  6.   overflow: hidden;
  7.   box-sizing: border-box;
  8.   height: 45px;
  9.   position: relative;
  10.   cursor: pointer;
  11. }
  12.  
  13. .marquee-sibling {
  14.   padding: 0;
  15.   background: #3BB0D6;
  16.   width: 20%;
  17.   height: 45px;
  18.   line-height: 42px;
  19.   font-size: 12px;
  20.   font-weight: normal;
  21.   color: #ffffff;
  22.   text-align: center;
  23.   float: left;
  24.   left: 0;
  25.   z-index: 2000;
  26. }
  27.  
  28. .marquee,
  29. *[class^="marquee"] {
  30.   display: inline-block;
  31.   white-space: nowrap;
  32.   position: absolute;
  33. }
  34.  
  35. .marquee { margin-left: 25%; }
  36.  
  37. .marquee-content-items {
  38.   display: inline-block;
  39.   padding: 5px;
  40.   margin: 0;
  41.   height: 45px;
  42.   position: relative;
  43. }
  44.  
  45. .marquee-content-items li {
  46.   display: inline-block;
  47.   line-height: 35px;
  48.   color: #fff;
  49. }
  50.  
  51. .marquee-content-items li:after {
  52.   content: "|";
  53.   margin: 0 1em;
  54. }

初始化插件:

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

  1. $(function (){
  2.   createMarquee();
  3. });

配置参数:

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

  1. $(function (){
  2.  
  3.   createMarquee({
  4.  
  5.     // controls the speed at which the marquee moves
  6.     duration:30000, 
  7.  
  8.     // right margin between consecutive marquees
  9.     padding:20, 
  10.  
  11.     // class of the actual div or span that will be used to create the marquee - 
  12.     // multiple marquee items may be created using this item's content. 
  13.     // This item will be removed from the dom
  14.     marquee_class:'.example-marquee', 
  15.  
  16.     // the container div in which the marquee content will animate. 
  17.     container_class: '.example-container', 
  18.  
  19.     // a sibling item to the marqueed item  that affects - 
  20.     // the end point position and available space inside the container. 
  21.     sibling_class: '.example-sibling', 
  22.  
  23.     // Boolean to indicate whether pause on hover should is required. 
  24.     hover: false
  25.  
  26.   });
  27.  
  28. });

jQuery 简单文字跑马灯特效

已有 760 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!