jquery.fullPage.js全屏滚动插件的使用方法

兼容性:

  1. 支持 IE8+ 及其他现代浏览器。

主要功能:

1.支持鼠标滚动;

2.支持前进后退键盘控制;

3.多个回调函数;

4.支持手机.移动设备;

5.支持窗口缩放自动调整;

6.可设置滚动宽度、背景颜色、滚动速度、循环选项、回调、文本对齐方式等等;

7.支持CSS3动画;

github下载地址:https://github.com/alvarotrigo/fullPage.js

滚屏里面的效果,都是写在回调函数中的;

配置表:

1.选项

选项 类型 默认值 说明
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

2.方法:

  • moveSectionUp() 向上滚动
  • moveSectionDown() 向下滚动
  • moveTo(section, slide) 滚动到
  • moveSlideRight() slide 向右滚动
  • moveSlideLeft() slide 向左滚动
  • setAutoScrolling() 设置页面滚动方式,设置为 true 时自动滚动
  • setAllowScrolling() 添加或删除鼠标滚轮/触控板控制
  • setKeyboardScrolling()添加或删除键盘方向键控制
  • setScrollingSpeed() 定义以毫秒为单位的滚动速度

3、回调函数

名称 说明
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个参数
个别代码示例:
$(function(){
    //fullpage.js全屏滚动插件效果;
    $('#dowebok').fullpage({
        sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90'],
        //滚动到某一屏后调用js代码
        afterLoad: function(anchorLink, index){
            if(index == 2){
                //进入第二个页面左边的div出现的效果;
                $('.animation_effect .left').delay(500).animate({
                    width: '60%'
                }, 1500, 'easeOutExpo');
                //进入第二个页面右边三个div出现的效果;
                $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').delay(500).animate({
                    width:'40%'
                },1500,'easeOutExpo');
                //鼠标进入左边的div,左边的div和右边三个div宽度发生变化;
                $('.animation_effect .left').mouseover(function(){
                    $(this).stop().animate({
                        width:'69%'
                    },1500, 'easeOutExpo');
                    $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({
                        width:'31%'
                    },1500,'easeOutExpo')
                });
                //鼠标离开左边的div,左边div和右边div宽度发生变化;
                $('.animation_effect .left').mouseout(function(){
                    $(this).stop().animate({
                        width:'60%'
                    },1500, 'easeOutExpo');
                    $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({
                        width:'40%'
                    },1500,'easeOutExpo')
                });
                //鼠标在左边的left的div中指定的坐标内移动的时候;
                $('.left').mousemove(function(e){
                    //console.log(e.offsetX +":" + e.offsetY)
                    if(e.offsetX>460){
                        //$('.animation_effect .left').stop().animate({
                        //    width:'69-460'+e.offsetX+'%'
                        //},1500, 'easeOutExpo');
                        console.log("dasfaf")

                    }
                })
                //鼠标进入右边的三个div,四个div出现的效果
                $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').mouseover(function(){
                    $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({
                        width:'49%'
                    },1500,'easeOutExpo');
                    $('.animation_effect .left').stop().animate({
                        width:'51%'
                    },1500, 'easeOutExpo');
                })
                //鼠标离开右边的三个div,四个div出现的效果;
                $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').mouseout(function(){
                    $('.animation_effect .top,.animation_effect .center,.animation_effect .bottom').stop().animate({
                        width:'40%'
                    },1500,'easeOutExpo');
                    $('.animation_effect .left').stop().animate({
                        width:'60%'
                    },1500, 'easeOutExpo');
                })
            }
            //当页面在首页的时候,点击视频关闭按钮,出现的效果;
            if(index == 1){
            
            }
            if(index == 4){
                $('.section4').find('p').fadeIn(2000);
            }
        },
        //滚动到某一屏前,或者这一屏幕滚动过后执行的js代码;
        onLeave: function(index, direction){
            if(index == '2'){
                $('.left').delay(450).animate({
                    width: '100%'
                }, 1500, 'easeOutExpo');
                $('.top,.center,.bottom').delay(450).animate({
                    width:'0'
                },1500,'easeOutExpo')
            }
            if(index == '3'){
                $('.section3').find('p').delay(500).animate({
                    bottom: '-120%'
                }, 1500, 'easeOutExpo');
            }
            if(index == '4'){
               $('.section4').find('p').fadeOut(2000);
            }
        }
    });
});


猜你喜欢

转载自blog.csdn.net/sunlizhen/article/details/78727458