fullPage.js和fullPage都能實現全屏滾動,兩者區別是:fullPage.js需依賴於JQuery庫,而fullPage不須要依賴任何一個js庫,能夠單獨使用。javascript
fullPage.js是開源的JQuery插件庫,其Github地址:https://github.com/alvarotrigo/fullPage.jscss
1.1 引入文件html
<!-- 引入css --> <link rel="stylesheet" type="text/css" href="./fullPage.js-master/jquery.fullPage.css" /> <!-- fullpage.js依賴於jquery庫 --> <script type="text/javascript" src="./jquery.js"></script> <script type="text/javascript" src="./fullPage.js-master/jquery.fullPage.min.js"></script>
1.2 css:引入的css並非給元素設置樣式的,元素的樣式須要本身寫java
<style type="text/css"> body { color: #FFFFFF; } .section1 { background-color: #BFDA00; } .section2 { background-color: #2EBE21; } .section3 { background-color: #2C3E50; } .section4 { background-color: #FF9900; } </style>
1.3 html:每個section代碼一屏,默認從第一屏顯示,若須要自定義從某屏開始顯示,爲section添加active類。示例默認從第三屏顯示jquery
<div id="ido"> <div class="section section1"> <h1>每個section是一屏,這是第一屏</h3> </div> <div class="section section2"> <h1>每個section是一屏,這是第二屏</h3> </div> <div class="section section3 active"> <h1>每個section是一屏,這是第三屏</h3> </div> <div class="section section4"> <h1>每個section是一屏,這是第四屏</h3> </div> </div>
1.4 js:css3
<script type="text/javascript"> $(function() { $("#ido").fullpage(); }); </script>
效果:http://denon-7c931.coding.io/fullpagejs.htmlgit
1.5 能夠在某屏中再添加子滾動屏,藉助slide類。修改上述第二個section以下:github
<div class="section section2" style="text-align:center"> <h1 class="slide">第二屏的第一屏</h1> <h1 class="slide">第二屏的第二屏</h1> <h1 class="slide">第二屏的第三屏</h1> <h1 class="slide">第二屏的第四屏</h1> </div>
1.6 添加背景屏,在html添加兩個sectionweb
<div class="section section5"> <h1>每個section是一屏,這是第5屏--圖片背景</h3> </div> <div class="section section6"> <h1>每個section是一屏,這是第6屏--圖片背景</h3> </div>
添加csscss3動畫
.section5 { background: url(http://idowebok.u.qiniudn.com/77/1.jpg) 50%;} .section6 { background: url(http://idowebok.u.qiniudn.com/77/2.jpg) 50%;} 效果:http://denon-7c931.coding.io/bjfull.html (滾動到5和6屏)
1.7 循環演示:continuousVertical設置爲true
$(function() { $("#ido").fullpage( { continuousVertical: true }); });
效果:http://denon-7c931.coding.io/xhfull.html (滾動到第6屏,再向下滾動時自動回到第一屏)
1.8 綁定菜單:添加菜單項
<ul id="menu"> <li data-menuanchor="page1" class="active"><a href="#page1">第一屏</a></li> <li data-menuanchor="page2"><a href="#page2">第二屏</a></li> <li data-menuanchor="page3"><a href="#page3">第三屏</a></li> <li data-menuanchor="page4"><a href="#page4">第四屏</a></li> <li data-menuanchor="page5"><a href="#page5">第5屏</a></li> <li data-menuanchor="page6"><a href="#page6">第6屏</a></li> </ul>
添加css
#menu { margin: 0; padding: 0; position: fixed; left: 10px; top: 10px; list-style-type: none; z-index: 70;} #menu li { float: left; margin: 0 10px 0 0; font-size: 14px;} #menu a { float: left; padding: 10px 20px; background-color: #fff; color: #333; text-decoration: none;} #menu .active a { color: #fff; background-color: #333;}
修改js
$(function() { $("#ido").fullpage( { continuousVertical: true, //循環演示 //綁定菜單 anchors: ['page1', 'page2', 'page3', 'page4','page5','page6'], menu: '#menu', }); });
效果:http://denon-7c931.coding.io/memufull.html
1.9 導航演示:設置’navigation': true,
$(function() { $("#ido").fullpage( { continuousVertical: true, //循環演示 //綁定菜單 anchors: ['page1', 'page2', 'page3', 'page4','page5','page6'], menu: '#menu', // 導航 'navigation': true, }); });
效果:http://denon-7c931.coding.io/navfull.html (導航在右側)
若是須要配置easing和scrollOverflow,則須要引入額外的js(在vendors目錄下)
<!-- jquery.easings.min.js 用於 easing 參數,也能夠使用完整的 jQuery UI 代替,若是不須要設置 easing 參數,可去掉改文件 --> <script type="text/javascript" src="./fullPage.js-master/vendors/jquery.easings.min.js"></script> <!-- 若是 scrollOverflow 設置爲 true,則須要引入 jquery.slimscroll.min.js,通常狀況下不須要 --> <script type="text/javascript" src="./fullPage.js-master/vendors/jquery.slimscroll.min.js"></script>
fullPage 是一款不依賴任何 js 庫的全屏滾動組件,支持垂直/水平滾動、CSS3 旋轉/縮放動畫,支持 IE5.5+,支持移動設備。其Github地址:https://github.com/powy1993/fullpage
<script type="text/javascript" src="./fullpage-master/js/fullPage.min.js"></script>
1.1 垂直滾動
css
body { width: 100%; *cursor: default; overflow: hidden; font: 16px/1.5 "Microsoft YaHei"; } div,p { margin: 0; padding: 0; } ul { list-style: none; } #pageContain { overflow: hidden; } .page { display: none; width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0; } .contain { width: 100%; height: 100%; display: none; position: relative; z-index: 0; } .current .contain,.slide .contain { display: block; } .current { display: block; z-index: 1; } .slide { display: block; z-index: 2; } .page1 { background: #37c1e3; } .page2 { background: #009922; } .page3 { background: #992211; } .page4 { background: #ff00ff; } .page5 { background: #00ff00; } .page6 { background: #22ffff; } #navBar { z-index: 3; position: absolute; top: 10%; right: 3%; } #navBar .active { background: #ccc; } #navBar li { cursor: pointer; margin-bottom: 10px; transition: all .7s ease; border-radius: 50%; line-height: 40px; text-align: center; width: 40px; height: 40px; } h1 { text-align: center; margin-top: 20%; }
html
<div id="pageContain"> <div class="page page1 current"> <div class="contain"> <h1 class="txt">第一屏</h1> </div> </div> <div class="page page2"> <div class="contain"> <h1 class="txt">第二屏</h1> </div> </div> <div class="page page3"> <div class="contain"> <h1 class="txt">第三屏</h1> </div> </div> <div class="page page4"> <div class="contain"> <h1 class="txt">第四屏</h1> </div> </div> <div class="page page5"> <div class="contain"> <h1 class="txt">第五屏</h1> </div> </div> </div> <ul id="navBar"> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul>
js
var runPage; runPage = new FullPage({ id: 'pageContain', slideTime: 800, effect: { transform: { translate: 'Y' //垂直滾動,改成X則是水平滾動 }, opacity: [0, 1] }, mode: 'wheel, touch, nav:navBar', easing: 'ease' });
效果:http://denon-7c931.coding.io/fullpage.html
1.2 css3動畫:修改js就行
var runPage; runPage = new FullPage({ id: 'pageContain', slideTime: 800, effect: { transform: { translate: 'X', scale: [0, 1], rotate: [270, 0] }, opacity: [0, 1] }, mode: 'wheel, touch, nav:navBar', easing: 'ease' });
效果:http://denon-7c931.coding.io/fulldh.html
1.3 自動滾動,js修改以下
var runPage, interval, autoPlay; autoPlay = function(to) { clearTimeout(interval); interval = setTimeout(function() { runPage.go(to); }, 1000); } runPage = new FullPage({ id: 'pageContain', slideTime: 800, effect: { transform: { translate: 'X', scale: [0, 1], rotate: [270, 0] }, opacity: [0, 1] }, mode: 'wheel, touch, nav:navBar', easing: 'ease', callback: function(index, thisPage){ index = index + 1 > 3 ? 0 : index + 1; autoPlay(index); } }); interval = setTimeout(function() { runPage.go(runPage.thisPage() + 1); }, 1000);
效果:http://denon-7c931.coding.io/fullauto.html