滚动公告功能的实现

编程技术  /  houtizong 发布于 3年前   54

1.新建一个表

  create_table "notices", :force => true do |t|     t.string   "title"    t.text     "content"    t.integer  "user_id"    t.date     "expiration"    t.datetime "created_at", :null => false    t.datetime "updated_at", :null => false  end 

2.将jcarousellite_1.0.1c4.js文件放置在/vendor/assets/javascripts路径下

3.在application.js中

//= require jcarousellite_1.0.1c4$(function(){    /* notice */                   $("#notice").jCarouselLite({     vertical: true,                hoverPause: true,              visible: 1,    auto: 2000,    speed: 1000  });});

4.在layout.css.scss中

#notice {                        border: 1px solid #eee;        text-align: center;            font-size: 16px;                 a {    color: green;                  text-decoration: none;           &:hover {                        background: #fff;    }  }                                                                                                                                          } 

5.在notice.rb中

  def self.recent    Notice.limit(10)  end           def self.avialable    Notice.where('expiration >= ?', Date.today)  end           def expired?    created_at < 7.days.ago.to_date  end 

6.在application.html.haml中

      - if Notice.avialable.size > 0                                                                                                                 #notice                          %ul            - Notice.avialable.each do |n|                %li= link_to "[ #{n.created_at.strftime('%m-%d')} ] #{n.title}", n

备注:

jcarousellite是一款jquery插件,可以控制文档元素滚动,丰富的参数设置可以控制滚动的更多细节,是一款不可多得的滚动插件。

 

使用方法:

 

页头调用:

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="js/jcarousellite_1.0.1.min.js"></script>

$(document).ready(function(){

    $(".类名").jCarouselLite({

        btnNext: ".next",

        btnPrev: ".prev"

    });

});

html:

<div class="类名">

  <ul>

    <li></li>

  </ul>

</div>

 

参数说明:

 

btnPrev     string 上一个按钮的class名, 比如  btnPrev: ".prev"

 

btnNext     string 下一个按钮的class名, 比如  btnPrev: ".prev"

 

btnGo       array  自定义滚动位置,类似幻灯片效果置,有选项卡,按照数组顺序,依次为按钮1按钮2按钮N,如以下,class名为1的按钮是第一个按钮:[".1", ".2"]

 

mouseWheel  bool   鼠标滑是否可以轮控制上下滚动,可选:false,true,默认false

 

auto        int    指定多少秒内容定期自动滚动。默认为空(null),是不滚动,如果设定的,单位为毫秒,如1秒为1000

 

speed       int    滑动的速度,可以尝试800 1000 1500,设置成0将删除效果

 

easing      string 缓冲效果名称,如:easing: "bounceout",需要jquery中的easing pluin(缓冲插件实现),只适用于jq1.2

 

vertical    bool   是否垂直滚动,可选:false,true,默认false

 

circular    bool   是否循环滚动,默认为true,如果为false,滚动到最后一个将停止滚动

 

visible     int    可见数量,可以为小数,如2.5为2.5个li

 

start       int    开始的地方,默认是0

 

scroll      int    每次滚动的li数量

 

beforeStart func   滚动开始时回调的函数,可以传入对象参数 beforeStart: function(a) { alert("开始的对象是:" + a)}

 

afterEnd    func   滚动结束时回调的函数,使用方法同上

 

上一篇:echo
下一篇:crontab

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客