時間:2023-09-05 20:00:01 | 來源:網(wǎng)站運(yùn)營
時間:2023-09-05 20:00:01 來源:網(wǎng)站運(yùn)營
基于jQuery的全屏滾動插件fullPage.js:<link rel="stylesheet" type="text/css" href="/fullpage/jquery.fullPage.css" /><script src="/fullpage/jquery.min.js"></script><script type="text/javascript" src="/fullpage/jquery.fullPage.js"></script>
如果你需要自定義頁面滾動的效果,你需要引入jquery.easings.min.js文件。<script src="/fullpage/jquery.easings.min.js"></script>
對于內(nèi)容比較多的頁面,可以設(shè)置右側(cè)的滾動條,但是默認(rèn)情況下無法滾動,你需要jquery.slimscroll.min.js文件來自定義滑條滾動效果。<script type="text/javascript" src="/fullpage/jquery.slimscroll.min.js"></script>
最后,如果你不想下載到項(xiàng)目中,您可以使用開源項(xiàng)目CDN服務(wù),F(xiàn)ullpage在CDNJS的地址:https://cdnjs.com/libraries/fullPage.js<div id="fullpage'"><div class="section">Some section</div><div class="section">Some section</div><div class="section">Some section</div><div class="section">Some section</div></div>
假如你需要讓某一個section作為首頁的第一屏展示,你只需要給這個section添加一個active的類,F(xiàn)ullpage會自動優(yōu)先展示這個屏幕,例如定義下面的代碼:<div class="section active">Some section</div>
Fullpage自帶左右滑動的幻燈片,只需要在section中添加DIV元素,并且給DIV元素添加slide類,F(xiàn)Ullpage會自動生成幻燈片特效,例如下面的代碼:<div class="section"><div class="slide"> Slide 1 </div><div class="slide"> Slide 2 </div><div class="slide"> Slide 3 </div><div class="slide"> Slide 4 </div></div>
3、初始化Fullpage$(document).ready(function() {$('#fullpage').fullpage();});
所有的選項(xiàng)設(shè)置更復(fù)雜的初始化可能看起來像這樣:$(document).ready(function() { $('#fullpage').fullpage({ //Navigation menu: false,//綁定菜單,設(shè)定的相關(guān)屬性與anchors的值對應(yīng)后,菜單可以控制滾動,默認(rèn)為false。 anchors:['firstPage', 'secondPage'],//anchors定義錨鏈接,默認(rèn)為[] lockAnchors: false,//是否鎖定錨鏈接,默認(rèn)為false,設(shè)為true后鏈接地址不會改變 navigation: false,//是否顯示導(dǎo)航,默認(rèn)為false navigationPosition: 'right',//導(dǎo)航小圓點(diǎn)的位置 navigationTooltips: ['firstSlide', 'secondSlide'],//導(dǎo)航小圓點(diǎn)的提示 showActiveTooltip: false,//是否顯示當(dāng)前頁面的tooltip信息 slidesNavigation: true,//是否顯示橫向幻燈片的導(dǎo)航,默認(rèn)為false slidesNavPosition: 'bottom',//橫向?qū)Ш降奈恢?,默認(rèn)為bottom,可以設(shè)置為top或bottom //Scrolling css3: true,//是否使用CSS3 transforms來實(shí)現(xiàn)滾動效果,默認(rèn)為true scrollingSpeed: 700,//設(shè)置滾動速度,單位毫秒,默認(rèn)700 autoScrolling: true,//是否使用插件的滾動方式,默認(rèn)為true,若為false則會出現(xiàn)瀏覽器自帶滾動條 fitToSection: true,//設(shè)置是否自適應(yīng)整個窗口的空間,默認(rèn)值:true scrollBar: false,//是否包含滾動條,默認(rèn)為false,若為true瀏覽器自帶滾動條出現(xiàn) easing: 'easeInOutCubic',//定義頁面section滾動的動畫方式,若修改此項(xiàng)需引入jquery.easing插件 easingcss3: 'ease',//定義頁面section滾動的過渡效果,若修改此項(xiàng)需引入第三方插件 loopBottom: false,//滾動到最低部后是否連續(xù)滾動到頂部,默認(rèn)為false loopTop: false,//滾動到最頂部后是否連續(xù)滾動到底部,默認(rèn)為false loopHorizontal: true,//橫向slide幻燈片是否循環(huán)滾動,默認(rèn)為true continuousVertical: false,//是否循環(huán)滾動,不兼容loopTop和loopBottom選項(xiàng) normalScrollElements: '#element1, .element2',//避免自動滾動,滾動時的一些元素,例如百度地圖 scrollOverflow: false,//內(nèi)容超過滿屏后是否顯示滾動條,true則顯示滾動條,若需滾動查看內(nèi)容還需要jquery.slimscroll插件的配合 touchSensitivity: 15,//在移動設(shè)備中滑動頁面的敏感性,默認(rèn)為5最高100,越大越難滑動 normalScrollElementTouchThreshold: 5, //Accessibility keyboardScrolling: true,//是否可以使用鍵盤方向鍵導(dǎo)航,默認(rèn)為true animateAnchor: true,//錨鏈接是否可以控制滾動動畫,默認(rèn)為true,若為false則錨鏈接定位失效 recordHistory: true,//是否記錄歷史,默認(rèn)為true,瀏覽器的前進(jìn)后退可導(dǎo)航。若autoScrolling:false,那么這個屬性將被關(guān)閉 //Design controlArrows: true,//定義是否通過箭頭來控制slide,默認(rèn)true verticalCentered: true,//定義每一頁的內(nèi)容是否垂直居中,默認(rèn)true resize : false,//字體是否隨窗口縮放而縮放,默認(rèn)false sectionsColor : ['#ccc', '#fff'],//為每個section設(shè)置background-color屬性 paddingTop: '3em',設(shè)置每一個section頂部的padding,默認(rèn)為0 paddingBottom: '10px',設(shè)置每一個section底部的padding,默認(rèn)為0 fixedElements: '#header, .footer',固定元素,默認(rèn)為null,需要配置一個jquery選擇器,在頁面滾動時,fixElements設(shè)置的元素不滾動 responsiveWidth: 0, responsiveHeight: 0, //Custom selectors sectionSelector: '.section',//section選擇器。默認(rèn)為.section slideSelector: '.slide',//slide選擇器,默認(rèn)為.slide //events onLeave: function(index, nextIndex, direction){}, afterLoad: function(anchorLink, index){}, afterRender: function(){}, afterResize: function(){}, afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex){}, onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){} });});
<ul id="myMenu"> <li data-menuanchor="firstPage" class="active"><a href="#firstPage">First section</a></li> <li data-menuanchor="secondPage"><a href="#secondPage">Second section</a></li> <li data-menuanchor="thirdPage"><a href="#thirdPage">Third section</a></li> <li data-menuanchor="fourthPage"><a href="#fourthPage">Fourth section</a></li></ul>
$('#fullpage').fullpage({ anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'], menu: '#myMenu'});
注意:注意這個自定義的菜單代碼應(yīng)該放置到插件設(shè)置的內(nèi)容外面,避免因?yàn)榕虐娌患嫒輪栴}可以使用css3:true,否則將被附加到body的插件本身。<script type="text/javascript" src="vendors/jquery.slimscroll.min.js"></script><script type="text/javascript" src="jquery.fullPage.js"></script>
touchSensitivity$('#fullpage').fullpage({ sectionsColor: ['#f2f2f2', '#4BBFC3', '#7BAABE', 'whitesmoke', '#000'],});
如果設(shè)置的參數(shù)不對稱,比如屏幕個數(shù)多余設(shè)置的顏色個數(shù),那么多余的屏幕默認(rèn)沒有背景顏色,如果屏幕個數(shù)少于設(shè)置的顏色個數(shù),那么多余的顏色將不顯示。$('#fullpage').fullpage({ onLeave: function(index, nextIndex, direction){ var leavingSection = $(this); //after leaving section 2 if(index == 2 && direction =='down'){ alert("Going to section 3!"); } else if(index == 2 && direction == 'up'){ alert("Going to section 1!"); } }});
取消section的滾動$('#fullpage').fullpage({ onLeave: function(index, nextIndex, direction){ //it won't scroll if the destination is the 3rd section if(nextIndex == 3){ return false; } }});
afterLoad (anchorLink, index)$('#fullpage').fullpage({ anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'], afterLoad: function(anchorLink, index){ var loadedSection = $(this); //using index if(index == 3){ alert("Section 3 ended loading"); } //using anchorLink if(anchorLink == 'secondSlide'){ alert("Section 2 ended loading"); } }});
afterRender()$('#fullpage').fullpage({ afterRender: function(){ var pluginContainer = $(this); alert("The resulting DOM structure is ready"); }});
afterResize()$('#fullpage').fullpage({ afterResize: function(){ var pluginContainer = $(this); alert("The sections have finished resizing"); }});
afterSlideLoad (anchorLink, index, slideAnchor, slideIndex)$('#fullpage').fullpage({ anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'], afterSlideLoad: function( anchorLink, index, slideAnchor, slideIndex){ var loadedSlide = $(this); //first slide of the second section if(anchorLink == 'secondPage' && slideIndex == 1){ alert("First slide loaded"); } //second slide of the second section (supposing #secondSlide is the //anchor for the second slide if(index == 2 && slideIndex == 'secondSlide'){ alert("Second slide loaded"); } }});
onSlideLeave (anchorLink, index, slideIndex, direction, nextSlideIndex)$('#fullpage').fullpage({ onSlideLeave: function( anchorLink, index, slideIndex, direction, nextSlideIndex){ var leavingSlide = $(this); //leaving the first slide of the 2nd Section to the right if(index == 2 && slideIndex == 0 && direction == 'right'){ alert("Leaving the fist slide!!"); } //leaving the 3rd slide of the 2nd Section to the left if(index == 2 && slideIndex == 2 && direction == 'left'){ alert("Going to slide 2! "); } }});
取消slide滑動 $.fn.fullpage.moveSectionUp();//向上滾動一頁 $.fn.fullpage.moveSectionDown();//向下滾動一頁 $.fn.fullpage.moveTo(section,slide);//從1開始,slide從0開始 $.fn.fullpage.silentMoveTo(section,slide);//和moveTo一樣,但是沒有滾動效果 $.fn.fullpage.moveSlideRight();//幻燈片向右滾動 $.fn.fullpage.moveSlideLeft();//幻燈片向左滾動 $.fn.fullpage.setAutoScrolling(boolean);//動態(tài)設(shè)置autoScrolling $.fn.fullpage.setLockAnchors(boolean);//動態(tài)設(shè)置lockAnchors $.fn.fullpage.setRecordHistory(boolean);//動態(tài)設(shè)置recordHistory $.fn.fullpage.setScrollingSpeed(milliseconds);//動態(tài)設(shè)置scrollingSpeed $.fn.fullpage.destory(type);//銷毀fullpage,type可以不寫或者使用all $.fn.fullpage.reBuild();/重新更新頁面和尺寸,用于ajax請求改變頁面結(jié)構(gòu)后重建效果
moveSectionUp()/*Scrolling to the section with the anchor link `firstSlide` and to the 2nd Slide */$.fn.fullpage.moveTo('firstSlide', 2); //Scrolling to the 3rd section in the site$.fn.fullpage.moveTo(3, 0); //Which is the same as$.fn.fullpage.moveTo(3);
silentMoveTo(section, slide)/*Scrolling to the section with the anchor link `firstSlide` and to the 2nd Slide */$.fn.fullpage.silentMoveTo('firstSlide', 2);
moveSlideRight()$.fn.fullpage.moveSlideRight();
moveSlideLeft()$.fn.fullpage.moveSlideLeft();
setAutoScrolling(boolean)$.fn.fullpage.setAutoScrolling(false);
setFitToSection(boolean)$.fn.fullpage.setFitToSection(false);
setLockAnchors(boolean)$.fn.fullpage.setLockAnchors(false);
setAllowScrolling(boolean, [directions])//disabling scrolling$.fn.fullpage.setAllowScrolling(false); //disabling scrolling down$.fn.fullpage.setAllowScrolling(false, 'down'); //disabling scrolling down and right$.fn.fullpage.setAllowScrolling(false, 'down, right');
setKeyboardScrolling(boolean, [directions])//disabling all keyboard scrolling$.fn.fullpage.setKeyboardScrolling(false); //disabling keyboard scrolling down$.fn.fullpage.setKeyboardScrolling(false, 'down'); //disabling keyboard scrolling down and right$.fn.fullpage.setKeyboardScrolling(false, 'down, right');
setRecordHistory(boolean)$.fn.fullpage.setRecordHistory(false);
setScrollingSpeed(milliseconds)$.fn.fullpage.setScrollingSpeed(700);
destroy(type)//destroy any plugin event (scrolls, hashchange in the URL...)$.fn.fullpage.destroy(); //destroy any plugin event and any plugin modification done over your original HTML markup.$.fn.fullpage.destroy('all');
reBuild()$.fn.fullpage.reBuild();
<img data-src="image.png"><video> <source data-src="video.webm" type="video/webm" /> <source data-src="video.mp4" type="video/mp4" /></video>
關(guān)鍵詞:滾動
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。