1.fullpage.js 下载地址
https://github.com/alvarotrigo/fullPage.js
2.fullPage.js 是一个基于 jQuery 的插件,它能够很方便、很轻松的制作出全屏网站,主要功能有:
- 支持鼠标滚动
- 支持前进后退和键盘控制
- 多个回调函数
- 支持手机、平板触摸事件
- 支持 CSS3 动画
- 支持窗口缩放
- 窗口缩放时自动调整
- 可设置滚动宽度、背景颜色、滚动速度、循环选项、回调、文本对齐方式等等
3.在相应的HTML页面中引入一下文件
<link rel="stylesheet" href="css/jquery.fullPage.css" rel="external nofollow" >
<script src="js/jquery.min.js"></script>
<!-- jquery.easings.min.js 是必须的,用于 easing 参数,也可以使用完整的 jQuery UI 代替 -->
<script src="js/jquery.easings.min.js"></script>
<!-- 如果 scrollOverflow 设置为 true,则需要引入 jquery.slimscroll.min.js,一般情况下不需要 -->
<script src="js/jquery.slimscroll.min.js"></script>
<script src="js/jquery.fullPage.js"></script>
4.<body>部分
<ul id="menu">
<li data-menuanchor="page1" class="active">
<a href="#page1" rel="external nofollow" >第一屏</a>
</li>
<li data-menuanchor="page2">
<a href="#page2" rel="external nofollow" >第二屏</a>
</li>
<li data-menuanchor="page3">
<a href="#page3" rel="external nofollow" >第三屏</a>
</li>
<li data-menuanchor="page4">
<a href="#page4" rel="external nofollow" >第四屏</a>
</li>
</ul>
$.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)
Demo Exactly the same as moveTo but in this case it performs the scroll without animation. A direct jump to the destination.
$.fn.fullpage.silentMoveTo('firstSlide', 2);
moveSlideRight()
Demo Scrolls the horizontal slider of the current section to the next slide:
$.fn.fullpage.moveSlideRight();
moveSlideLeft()
Demo Scrolls the horizontal slider of the current section to the previous slide:
$.fn.fullpage.moveSlideLeft();
setAutoScrolling(boolean)
Demo Sets the scrolling configuration in real time. Defines the way the page scrolling behaves. If it is set to true, it will use the "automatic" scrolling, otherwise, it will use the "manual" or "normal" scrolling of the site.
$.fn.fullpage.setAutoScrolling(false);
setFitToSection(boolean)
Demo Sets the value for the option fitToSection determining whether to fit the section in the screen or not.
$.fn.fullpage.setFitToSection(false);
fitToSection()
Demo Scrolls to the nearest active section fitting it in the viewport.
$.fn.fullpage.fitToSection();
setLockAnchors(boolean)
Demo Sets the value for the option lockAnchors determining whether anchors will have any effect in the URL or not.
$.fn.fullpage.setLockAnchors(false);
setAllowScrolling(boolean, [directions])
Demo Adds or remove the possibility of scrolling through sections/slides by using the mouse wheel/trackpad or touch gestures (which is active by default). Note this won't disable the keyboard scrolling. You would need to use setKeyboardScrolling for it.
directions: (optional parameter) Admitted values: all, up, down, left, right or a combination of them separated by commas like down, right. It defines the direction for which the scrolling will be enabled or disabled.
//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])
Demo Adds or remove the possibility of scrolling through sections by using the keyboard (which is active by default).
directions: (optional parameter) Admitted values: all, up, down, left, right or a combination of them separated by commas like down, right. It defines the direction for which the scrolling will be enabled or disabled.
//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)
Demo Defines whether to record the history for each hash change in the URL.
$.fn.fullpage.setRecordHistory(false);
setScrollingSpeed(milliseconds)
Demo Defines the scrolling speed in milliseconds.
$.fn.fullpage.setScrollingSpeed(700);
destroy(type)
Demo Destroys the plugin events and optionally its HTML markup and styles. Ideal to use when using AJAX to load content.
type: (optional parameter) can be empty or all. If all is passed, the HTML markup and styles used by fullpage.js will be removed. This way the original HTML markup, the one used before any plugin modification is made, will be maintained.
//destroying all Javascript events created by fullPage.js (scrolls, hashchange in the URL...)
$.fn.fullpage.destroy();
//destroying all Javascript events and any modification done by fullPage.js over your original HTML markup.
$.fn.fullpage.destroy('all');
reBuild()
Updates the DOM structure to fit the new window size or its contents. Ideal to use in combination with AJAX calls or external changes in the DOM structure of the site, specially when using scrollOverflow:true.
$.fn.fullpage.reBuild();
setResponsive(boolean)
Demo Sets the responsive mode of the page. When set to true the autoScrolling will be turned off and the result will be exactly the same one as when the responsiveWidth or responsiveHeight options get fired.
$.fn.fullpage.setResponsive(true);
responsiveSlides.toSections()
Extension of fullpage.js. Requires fullpage.js >= 2.8.5. Turns horizontal slides into vertical sections.
$.fn.fullpage.responsiveSlides.toSections();
responsiveSlides.toSlides()
Extension of fullpage.js. Requires fullpage.js >= 2.8.5. Turns back the original slides (now converted into vertical sections) into horizontal slides again.
$.fn.fullpage.responsiveSlides.toSlides();
Callbacks
Demo You can see them in action here.
afterLoad (anchorLink, index)
Callback fired once the sections have been loaded, after the scrolling has ended. Parameters:
anchorLink: anchorLink corresponding to the section.
index: index of the section. Starting from 1.
In case of not having anchorLinks defined in the plugin the index parameter would be the only one to use.
Example:
$('#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");
}
}
});
onLeave (index, nextIndex, direction)
This callback is fired once the user leaves a section, in the transition to the new section. Returning false will cancel the move before it takes place.
Parameters:
index: index of the leaving section. Starting from 1.
nextIndex: index of the destination section. Starting from 1.
direction: it will take the values up or down depending on the scrolling direction.
Example:
$('#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!");
}
}
});
Cancelling the scroll before it takes place
You can cancel the scroll by returning false on the onLeave callback:
$('#fullpage').fullpage({
onLeave: function(index, nextIndex, direction){
//it won't scroll if the destination is the 3rd section
if(nextIndex == 3){
return false;
}
}
});
afterRender()
This callback is fired just after the structure of the page is generated. This is the callback you want to use to initialize other plugins or fire any code which requires the document to be ready (as this plugin modifies the DOM to create the resulting structure). See FAQs for more info.
Example:
$('#fullpage').fullpage({
afterRender: function(){
var pluginContainer = $(this);
alert("The resulting DOM structure is ready");
}
});
afterResize()
This callback is fired after resizing the browser's window. Just after the sections are resized.
Example:
$('#fullpage').fullpage({
afterResize: function(){
var pluginContainer = $(this);
alert("The sections have finished resizing");
}
});
afterResponsive(isResponsive)
This callback is fired after fullpage.js changes from normal to responsive mode or from responsive mode to normal mode.
Parameters:
isResponsive: boolean that determines if it enters into responsive mode (true) or goes back to normal mode (false).
Example:
$('#fullpage').fullpage({
afterResponsive: function(isResponsive){
alert("Is responsive: " + isResponsive);
}
});
afterSlideLoad (anchorLink, index, slideAnchor, slideIndex)
Callback fired once the slide of a section have been loaded, after the scrolling has ended. Parameters:
anchorLink: anchorLink corresponding to the section.
index: index of the section. Starting from 1.
slideAnchor: anchor corresponding to the slide (in case there is)
slideIndex: index of the slide. Starting from 1. (the default slide doesn't count as slide, but as a section)
In case of not having anchorLinks defined for the slide or slides the slideIndex parameter would be the only one to use. Example:
$('#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)
This callback is fired once the user leaves an slide to go to another, in the transition to the new slide. Returning false will cancel the move before it takes place.
Parameters:
anchorLink: anchorLink corresponding to the section.
index: index of the section. Starting from 1.
slideIndex: index of the slide. Starting from 0.
direction: takes the values right or left depending on the scrolling direction.
nextSlideIndex: index of the destination slide. Starting from 0.
Example:
$('#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! ");
}
}
});
Cancelling a move before it takes place
You can cancel a move by returning false on the onSlideLeave callback. Same as when canceling a movement with onLeave.
6.配置
选项
选项 | 类型 | 默认值 | 说明 |
---|---|---|---|
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 |
方法
名称 | 说明 |
---|---|
moveSectionUp() | 向上滚动 |
moveSectionDown() | 向下滚动 |
moveTo(section, slide) | 滚动到 |
moveSlideRight() | slide 向右滚动 |
moveSlideLeft() | slide 向左滚动 |
setAutoScrolling() | 设置页面滚动方式,设置为 true 时自动滚动 |
setAllowScrolling() | 添加或删除鼠标滚轮/触控板控制 |
setKeyboardScrolling() | 添加或删除键盘方向键控制 |
setScrollingSpeed() | 定义以毫秒为单位的滚动速度 |
回调函数
名称 | 说明 |
---|---|
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个参数 |
到此这篇关于fullpage.js全屏滚动的具体使用方法的文章就介绍到这了,更多相关fullpage.js使用内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!