jquery.fullPage.js全屏滾動外掛的使用方法
阿新 • • 發佈:2018-11-07
相容性:
- 支援 IE8+ 及其他現代瀏覽器。
主要功能:
1.支援滑鼠滾動;
2.支援前進後退鍵盤控制;
3.多個回撥函式;
4.支援手機.移動裝置;
5.支援視窗縮放自動調整;
6.可設定滾動寬度、背景顏色、滾動速度、迴圈選項、回撥、文字對齊方式等等;
7.支援CSS3動畫;
github下載地址:https://github.com/alvarotrigo/fullPage.js
滾屏裡面的效果,都是寫在回撥函式中的;
配置表:
1.選項
選項 | 型別 | 預設值 | 說明 |
---|---|---|---|
verticalCentered | 字串 | true | 內容是否垂直居中 |
resize | 布林值 | false | 字型是否隨著視窗縮放而縮放 |
slidesColor | 函式 | 無 | 設定背景顏色 |
anchors | 陣列 | 無 | 定義錨鏈接 |
scrollingSpeed |
整數 | 700 | 滾動速度,單位為毫秒 |
easing | 字串 | easeInQuart | 滾動動畫方式 |
menu | 布林值 | false | 繫結選單,設定的相關屬性與 anchors 的值對應後,選單可以控制滾動 |
navigation | 布林值 | false | 是否顯示專案導航 |
navigationPosition | 字串 |
right | 專案導航的位置,可選 left 或 right |
navigationColor | 字串 | #000 | 專案導航的顏色 |
navigationTooltips | 陣列 | 空 | 專案導航的 tip |
slidesNavigation | 布林值 | false | 是否顯示左右滑塊的專案導航 |
slidesNavPosition | 字串 | bottom | 左右滑塊的專案導航的位置,可選 top 或 bottom |
controlArrowColor | 字串 | #fff | 左右滑塊的箭頭的背景顏色 |
loopBottom | 布林值 | false | 滾動到最底部後是否滾回頂部 |
loopTop | 布林值 | false | 滾動到最頂部後是否滾底部 |
loopHorizontal | 布林值 | true | 左右滑塊是否迴圈滑動 |
autoScrolling | 布林值 | true | 是否使用外掛的滾動方式,如果選擇 false,則會出現瀏覽器自帶的滾動條 |
scrollOverflow | 布林值 | false | 內容超過滿屏後是否顯示滾動條 |
css3 | 布林值 | false | 是否使用 CSS3 transforms 滾動 |
paddingTop | 字串 | 0 | 與頂部的距離 |
paddingBottom | 字串 | 0 | 與底部距離 |
fixedElements | 字串 | 無 | |
normalScrollElements | 無 | ||
keyboardScrolling | 布林值 | true | 是否使用鍵盤方向鍵導航 |
touchSensitivity | 整數 | 5 | |
continuousVertical | 布林值 | false | 是否迴圈滾動,與 loopTop 及 loopBottom 不相容 |
animateAnchor | 布林值 | true | |
normalScrollElementTouchThreshold | 整數 | 5 |
2.方法:
- moveSectionUp() 向上滾動
- moveSectionDown() 向下滾動
- moveTo(section, slide) 滾動到
- moveSlideRight() slide 向右滾動
- moveSlideLeft() slide 向左滾動
- setAutoScrolling() 設定頁面滾動方式,設定為 true 時自動滾動
- setAllowScrolling() 新增或刪除滑鼠滾輪/觸控板控制
- setKeyboardScrolling()新增或刪除鍵盤方向鍵控制
- setScrollingSpeed() 定義以毫秒為單位的滾動速度
3、回撥函式
名稱 | 說明 |
---|---|
afterLoad | 滾動到某一屏後的回撥函式,接收 anchorLink 和 index 兩個引數,anchorLink 是錨鏈接的名稱,index 是序號,從1開始計算 |
onLeave | 滾動前的回撥函式,接收 index、nextIndex 和 direction 3個引數:index 是離開的“頁面”的序號,從1開始計算;
nextIndex 是滾動到的“頁面”的序號,從1開始計算; direction 判斷往上滾動還是往下滾動,值是 up 或 down。 |
afterRender | 頁面結構生成後的回撥函式,或者說頁面初始化完成後的回撥函式 |
afterSlideLoad | 滾動到某一水平滑塊後的回撥函式,與 afterLoad 類似,接收 anchorLink、index、slideIndex、direction 4個引數 |
onSlideLeave | 某一水平滑塊滾動前的回撥函式,與 onLeave 類似,接收 anchorLink、index、slideIndex、direction 4個引數 |
$(function(){ //fullpage.js全屏滾動外掛效果; $('#dowebok').fullpage({ sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90'], //滾動到某一屏後呼叫js程式碼 afterLoad: function(anchorLink, index){ if(index == 2){ //進入第二個頁面左邊的div出現的效果; $('.animation_effect .left').delay(500).animate({ width: '60%' }, 1500, 'easeOutExpo'); //進入第二個頁面右邊三個div出現的效果; $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').delay(500).animate({ width:'40%' },1500,'easeOutExpo'); //滑鼠進入左邊的div,左邊的div和右邊三個div寬度發生變化; $('.animation_effect .left').mouseover(function(){ $(this).stop().animate({ width:'69%' },1500, 'easeOutExpo'); $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({ width:'31%' },1500,'easeOutExpo') }); //滑鼠離開左邊的div,左邊div和右邊div寬度發生變化; $('.animation_effect .left').mouseout(function(){ $(this).stop().animate({ width:'60%' },1500, 'easeOutExpo'); $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({ width:'40%' },1500,'easeOutExpo') }); //滑鼠在左邊的left的div中指定的座標內移動的時候; $('.left').mousemove(function(e){ //console.log(e.offsetX +":" + e.offsetY) if(e.offsetX>460){ //$('.animation_effect .left').stop().animate({ // width:'69-460'+e.offsetX+'%' //},1500, 'easeOutExpo'); console.log("dasfaf") } }) //滑鼠進入右邊的三個div,四個div出現的效果 $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').mouseover(function(){ $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({ width:'49%' },1500,'easeOutExpo'); $('.animation_effect .left').stop().animate({ width:'51%' },1500, 'easeOutExpo'); }) //滑鼠離開右邊的三個div,四個div出現的效果; $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').mouseout(function(){ $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({ width:'40%' },1500,'easeOutExpo'); $('.animation_effect .left').stop().animate({ width:'60%' },1500, 'easeOutExpo'); }) } //當頁面在首頁的時候,點選視訊關閉按鈕,出現的效果; if(index == 1){ } if(index == 4){ $('.section4').find('p').fadeIn(2000); } }, //滾動到某一屏前,或者這一螢幕滾動過後執行的js程式碼; onLeave: function(index, direction){ if(index == '2'){ $('.left').delay(450).animate({ width: '100%' }, 1500, 'easeOutExpo'); $('.top,.center,.bottom').delay(450).animate({ width:'0' },1500,'easeOutExpo') } if(index == '3'){ $('.section3').find('p').delay(500).animate({ bottom: '-120%' }, 1500, 'easeOutExpo'); } if(index == '4'){ $('.section4').find('p').fadeOut(2000); } } }); });