fullpage.js全屏滾動外掛程式使用執行個體,fullpage.js全屏

來源:互聯網
上載者:User

fullpage.js全屏滾動外掛程式使用執行個體,fullpage.js全屏

剛做好公司網站,通過全屏滾動,顯著提高了官網的瀏覽體驗。遂總結一下使用fullpage.js的方法。歡迎指正

一. fullpage.js簡介

 

fullpage.js是一套實現瀏覽器全屏滾動的js外掛程式,很多網站現在都使用了其來實現較好的瀏覽體驗。
 可以實現的功能:

 •支援前進後退和鍵盤控制
 •多個回呼函數
 •支援手機、平板觸摸事件
 •支援 CSS3 動畫
 •支援視窗縮放
 •視窗縮放時自動調整
 •可設定滾動寬度、背景顏色、捲動速度、迴圈選項、回調、文本對齊等等 

二.外掛程式下載

npm|npm install fullpage.js
bower|bower install fullpage.js
github|https://github.com/alvarotrigo/fullPage.js/
cdn|https://cdnjs.com/libraries/fullPage.js

三.檔案引入方式 

<link rel="stylesheet" href="css/jquery.fullPage.css"><script src="js/jquery.min.js"></script><script src="js/jquery.fullPage.js"></script>

注意:一定要先引入jquery,再引入fullpage。我剛開始寫demo的時候,因為順序錯誤,導致不能實現效果,瀏覽器報錯fullpage.js中的jquery未定義。 

四. 寫html代碼 

<div id="fullpage">    <div class="section">section1</div>    <div class="section">section2</div>    <div class="section">section3</div>    <div class="section">section4</div></div> 

所有的內容包含在ID名為fullpage的div內,不可以給body加此。
 類名為.section的div元素便是一個單頁,通過滑鼠滾輪和鍵盤可控制不同頁面之間的替換,也可設定列表導航。
 同時,如果要在一個頁面內做橫向的切屏效果,可以在div.section中添加div.slide。代碼如下: 

<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> 

五.初始化fullpage 

$(document).ready(function() {  $('#fullpage').fullpage(    {      .......      //options 詳情參看https://github.com/alvarotrigo/fullPage.js/    }    );}); 

設定側邊欄導航 

這個導航一般網站設計都會有,fullpage預設的導航樣式是小黑點,也支援設定別的樣式。

<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>
 #myMenu{  position:fixed;    ...} $('#fullpage').fullpage({  anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],  menu: '#myMenu'}); 

六.遇到的問題及解決思路 

在網站做好後測試時發現,剛進入頁面,在fullpage.js檔案未完成初始化之前,此時DOM css正在載入中,所有已顯示的樣式內容會擠在一塊,當載入完之後就會恢複。如果網站最佳化過關且網速給力的話,這段時間會比較短,但仍會帶來不好的使用者體驗。
 遂嘗試各種解決方案:
 1.div.section
 section{overflow:hidden}
經測,這個方法並沒有什麼卵用。

 2.設定一個空白遮罩,在所有頁面完成之前只顯示該遮罩,主題內容隱藏,待載入完成之後,內容顯示遮罩去除。當然也可以在遮罩層設定網站相關內容。
具體的實現方法demo: 

<html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">    <title>無標題文檔</title>    <script language="javascript" type="text/javascript">        function showAllContent(status1,status2){         document.getElementByIdx("showContent").style.display=status1;         document.getElementByIdx("showLoad").style.display=status2;      }    </script>  </head><body onLoad='showAllContent("","none")'><div id="showLoad" style="z-index:2; display:block; width:auto; height:auto;">頁面載入中......</div><div id="showContent" style="z-index:1; ">//最終要顯示的內容
</div>
<script>showAllContent("none","");</script>
</body>
</html>

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.