jQuery插件Timelinr 實現(xiàn)時間軸特效
前言
這是一款可用于展示歷史和計劃的時間軸插件,尤其比較適合一些網(wǎng)站展示發(fā)展歷程、大事件等場景。該插件基于jQuery,可以滑動切換、水平和垂直滾動、支持鍵盤方向鍵。經(jīng)過擴展后可以支持鼠標滾輪事件。
HTML
我們在body中建立一個div#timeline作為展示區(qū),#dates為時間軸,示例中我們用年份作為主軸,#issues作為內(nèi)容展示區(qū),即展示對應(yīng)主軸點年份的內(nèi)容,注意id對應(yīng)上。
<div id="timeline">
<ul id="dates">
<li><a href="#2011">2011</a></li>
<li><a href="#2012">2012</a></li>
</ul>
<ul id="issues">
<li id="2011">
<p>Lorem ipsum.</p>
</li>
<li id="2012">
<p>分享生活 留住感動</p>
</li>
</ul>
<a href="#" id="next">+</a> <!-- optional -->
<a href="#" id="prev">-</a> <!-- optional -->
</div>
jQuery Timelinr依賴于jQuery,所以在html中要先載入jQuery庫和jQuery Timelinr插件。
<script type="text/javascript" src="jquery-1.8.2.min.js"></script> <script type="text/javascript" src="jquery.timelinr-0.9.53.js"></script>
css
接下來用CSS來布局,你可以設(shè)置不同的CSS來控制時間軸是否橫向排列還是縱向排列,根據(jù)需求自由發(fā)揮,以下給出的是縱向排列,即用于垂直滾動的樣式。
#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
調(diào)用時間軸插件非常簡單,執(zhí)行以下代碼:
$(function(){
$().timelinr({
orientation:'vertical'
});
});
jQuery Timelinr提供了很多可設(shè)置的選項,可以根據(jù)需要進行設(shè)置。如圖所示:

支持滾輪驅(qū)動
此外,當前的jQuery Timelinr并不支持鼠標滾輪驅(qū)動,其實我們可以稍微對插件做下擴展就可以支持鼠標滾輪驅(qū)動,這里需要用到滾輪時間插件:jquery.mousewheel.js
下載該插件后,在頁面中導入:
<script src="jquery.mousewheel.js"></script>
然后,修改jquery.timelinr-0.9.53.js,大概在260行位置加入如下代碼:
//--------------Added by helloweba.com 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,當設(shè)置了支持滾輪事件時,滾輪向上,相當于點擊prevButton,滾輪向下,相當于點擊了nextButton。
最后使用以下代碼后,整個時間軸就可支持滾輪事件了
$(function(){
$().timelinr({
mousewheel: 'true'
});
});
相關(guān)文章
jQuery拋物線運動實現(xiàn)方法(附完整demo源碼下載)
這篇文章主要介紹了jQuery拋物線運動實現(xiàn)方法,以完整實例形式分析了jQuery物體運動的實現(xiàn)技巧,并附帶了完整的demo源碼供讀者下載參考,需要的朋友可以參考下2016-01-01
vue登錄頁面cookie的使用及頁面跳轉(zhuǎn)代碼
這篇文章主要介紹了vue登錄頁面cookie的使用及頁面跳轉(zhuǎn)代碼功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07
ASP.NET jQuery 實例5 (顯示CheckBoxList成員選中的內(nèi)容)
這章我們主要看下如何通過jQuery來獲取CheckBoxList成員內(nèi)容2012-01-01
jquery checkbox的相關(guān)操作總結(jié)
這篇文章主要介紹了jquery checkbox的相關(guān)操作總結(jié)的相關(guān)資料,需要的朋友可以參考下2016-10-10

