php jquery 时间轴,jQuery时间轴插件:jQuery Timelinr

HTML

我们在body中建立一个div#timeline作为展示区,#dates为时间轴,示例中我们用年份作为主轴,#issues作为内容展示区,即展示对应主轴点年份的内容,注意id对应上。

  • Lorem ipsum.

  • 分享生活 留住感动

jQuery Timelinr依赖于jQuery,所以在html中要先载入jQuery库和jQuery Timelinr插件。

CSS

接下来用CSS来布局,你可以设置不同的CSS来控制时间轴是否横向排列还是纵向排列,根据需求自由发挥,以下给出的是纵向排列,即用于垂直滚动的样式。

#timeline {width: 760px;height: 440px;overflow: hidden;margin: 40px auto;

position: relative;background: url('dot.gif') 110px top repeat-y;}

#dates {width: 115px;height: 440px;overflow: hidden;float: left;}

#dates li {list-style: none;width: 100px;height: 100px;line-height: 100px;font-size: 24px;

padding-right:20px; text-align:right; background: url('biggerdot.png') 108px center no-repeat;}

#dates a {line-height: 38px;padding-bottom: 10px;}

#dates .selected {font-size: 38px;}

#issues {width: 630px;height: 440px;overflow: hidden;float: right;}

#issues li {width: 630px;height: 440px;list-style: none;}

#issues li h1 {color: #ffcc00;font-size: 42px; height:52px; line-height:52px;

text-shadow: #000 1px 1px 2px;}

#issues li p {font-size: 14px;margin: 10px;line-height: 26px;}

jQuery

调用时间轴插件非常简单,执行以下代码:

$(function(){

$().timelinr({

orientation:'vertical'

});

});

jQuery Timelinr提供了很多可设置的选项,可以根据需要进行设置。

选项

描述

默认值

orientation

时间轴方向,可为水平(horizontal)或垂直(vertical)

horizontal

containerDiv

时间轴展示主区域ID

#timeline

datesDiv

时间轴主轴ID

#dates

datesSelectedClass

当前主轴轴点的样式

selected

datesSpeed

主轴滚动速度,可为100~1000之间的数字,或者设置为'slow', 'normal' or 'fast'

normal

issuesDiv

主要内容展示区

#issues

issuesSpeed

对应内容区的滚动速度,可为100~1000之间的数字,或者设置为'slow', 'normal' or 'fast'

fast

issuesTransparency

内容区的切入时的透明度,在0~1之间取值

0.2

issuesTransparencySpeed

内容区的切入时的透明度变化速度,100~1000之间的数字

500

prevButton

用于点击展示前一项内容的按钮ID

#prev

nextButton

用于点击展示后一项内容的按钮ID

#next

arrowKeys

是否支持方向键,true or false

false

startAt

初始化起点,即初始化轴点位置,数字

1

autoPlay

是否自动滚动,true or false

false

autoPlayDirection

滚动方向,forward or backward

forward

autoPlayPause

自动滚动时停留时间,毫秒

2000

支持滚轮驱动

此外,当前的jQuery Timelinr并不支持鼠标滚轮驱动,其实我们可以稍微对插件做下扩展就可以支持鼠标滚轮驱动,这里需要用到滚轮时间插件:jquery.mousewheel.js

下载该插件后,在页面中导入。

然后,修改jquery.timelinr-0.9.53.js,大概在260行位置加入如下代码:

//--------------Added by helloweba.net 20130326----------

if(settings.mousewheel=="true") { //支持滚轮

$(settings.containerDiv).mousewheel(function(event, delta, deltaX, deltaY){

if(delta==1){

$(settings.prevButton).click();

}else{

$(settings.nextButton).click();

}

});

}

我们在示例中屏蔽了按钮prevButton和nextButton,当设置了支持滚轮事件时,滚轮向上,相当于点击prevButton,滚轮向下,相当于点击了nextButton。

然后在32行处加入初始化选项:

mousewheel: 'false'

最后使用以下代码后,整个时间轴就可支持滚轮事件了,查看demo。

$(function(){

$().timelinr({

mousewheel:'true'

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值