1. fullpage.js的主要功能
fullPage.js是一个基于jquery的插件,它能很方便的制作出全屏网站,github地址。
主要功能有:
- 支持鼠标滚动。
- 支持前后退和键盘控制。
- 多个回调函数。
- 支持手机,平板触摸事件。
- 支持css3动画。
- 支持窗口缩放。
- 窗口缩放时自动调整。
- 可设置滚动宽度,背景颜色,滚动速度,循环选项,回调,文本对齐方式等。
2. fullpage.js的使用
2.1 兼容性
fullpage.js是jQuery的插件,需要依赖jQuery,要求jQuery最低的版本是1.6+。浏览器能兼容到ie8+及其他现代浏览器。
2.2 下载fullpage.js
第一种方法: 直接下载压缩包,地址
第二种方法: 使用前端的包管理工具
// With bower
bower install fullpage.js
// With npm
npm install fullpage.js
第三种: CDNJS地址:
https://cdnjs.com/libraries/fullPage.js
2.3 引入文件及文件依赖关系
fullpage.js插件依赖:fullpage的css文件,jQuery,如果设置了options中css3: false*,如果你用除了jQuery的默认linear 和swing缓动的效果之外的缓动效果的话,需要添加 jQuery UI library。
引入依赖的文件,注意顺序!
<!--引入fullpage.js插件的样式,必须-->
<link rel="stylesheet" type="text/css" href="jquery.fullPage.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- 如果是ie8浏览器或者设置了css3: false 那么需要引入jQuery的easing缓动插件,默认可以省略就行了。 -->
<script src="vendors/jquery.easings.min.js"></script>
<!--引入jQuery的插件fullpage.js核心文件-->
<script type="text/javascript" src="jquery.fullPage.js"></script>
2.4 编写页面结构
编写html的页面结构,每个section独占一屏幕,默认显示第一屏。
<div id="fullpage">
<div class="section">第一屏</div>
<div class="section">第二屏</div>
<div class="section">第三屏</div>
<div class="section">第四屏</div>
</div>
如果需要从非第一屏开始显示,则需要给对应的section添加active样式类即可。
<div class="section active">第三屏</div>
2.5 编写初始化的脚本
$(function() {
$('#fullpage').fullpage();
});
完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>全屏插件</title>
<link rel="stylesheet" href="./js/fullpage/jquery.fullpage.css">
<script src="./js/jquery-1.11.3.min.js"></script>
<script src="./js/fullpage/jquery.fullpage.min.js"></script>
</head>
<body>
<div id="dowebok">
<div class="section">
<h3>第一屏</h3>
</div>
<div class="section">
<h3>第二屏</h3>
</div>
<div class="section">
<h3>第三屏</h3>
</div>
<div class="section">
<h3>第四屏</h3>
</div>
</div>
<script>
$(function () {
$('#dowebok').fullpage();
});
</script>
</body>
</html>
3. fullpage的初始化的设置
在初始化全屏插件的时候,有很多设置项。如下所示:
$(document).ready(function() {
$('#fullpage').fullpage({
//Navigation
menu: '#menu',
lockAnchors: false,
anchors:['firstPage', 'secondPage'],
navigation: false,
navigationPosition: 'right',
navigationTooltips: ['firstSlide', 'secondSlide'],
showActiveTooltip: false,
slidesNavigation: false,
slidesNavPosition: 'bottom',
//Scrolling
css3: true,
scrollingSpeed: 700,
autoScrolling: true,
fitToSection: true,
fitToSectionDelay: 1000,
scrollBar: false,
easing: 'easeInOutCubic',
easingcss3: 'ease',
loopBottom: false,
loopTop: false,
loopHorizontal: true,
continuousVertical: false,
continuousHorizontal: false,
scrollHorizontally: false,
interlockedSlides: false,
dragAndMove: false,
offsetSections: false,
resetSliders: false,
fadingEffect: false,
normalScrollElements: '#element1, .element2',
scrollOverflow: false,
scrollOverflowReset: false,
scrollOverflowOptions: null,
touchSensitivity: 15,
normalScrollElementTouchThreshold: 5,
bigSectionsDestination: null,
//Accessibility
keyboardScrolling: true,
animateAnchor: true,
recordHistory: true,
//Design
controlArrows: true,
verticalCentered: true,
sectionsColor : ['#ccc', '#fff'],
paddingTop: '3em',
paddingBottom: '10px',
fixedElements: '#header, .footer',
responsiveWidth: 0,
responsiveHeight: 0,
responsiveSlides: false,
parallax: false,
parallaxOptions: {type: 'reveal', percentage: 62, property: 'translate'},
//Custom selectors
sectionSelector: '.section',
slideSelector: '.slide',
lazyLoading: true,
//events
onLeave: function(index, nextIndex, direction){},
afterLoad: function(anchorLink, index){},
afterRender: function(){},
afterResize: function(){},
afterResponsive: function(isResponsive){},
afterSlideLoad: function(anchorLink, index, slideAnchor, slideIndex){},
onSlideLeave: function(anchorLink, index, slideIndex, direction, nextSlideIndex){}
});
});