您的位置:首页 > Web前端 > JQuery

jQuery时间轴插件:jQuery Timelinr

2015-06-16 11:43 691 查看
这是一款可用于展示历史和计划的时间轴插件,尤其比较适合一些网站展示发展历程、大事件等场景。该插件基于jQuery,可以滑动切换、水平和垂直滚动、支持键盘方向键。经过扩展后可以支持鼠标滚轮事件。

HTML

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

#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;}


View Code

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 falsefalse
startAt初始化起点,即初始化轴点位置,数字1
autoPlay是否自动滚动,true or falsefalse
autoPlayDirection滚动方向,forward or backwardforward
autoPlayPause自动滚动时停留时间,毫秒2000
支持滚轮驱动

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

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

<script src="jquery.mousewheel.js"></script>


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

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'
});
});


原文:/article/1207940.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: