fullpage.js全屏滚动的具体使用方法

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>
/*鼠标滚动换/*
<div id="dowebok">
    <div class="section">
        <h3>第一屏</h3>
        <p>fullPage.js — 绑定菜单演示</p>
    </div>
    <div class="section active">
        <h3>第二屏</h3>
        <p>请查看左上角,点击可以控制</p>
    </div>
    <div class="section">
        <h3>第三屏</h3>
        <p>绑定的菜单没有默认的样式,你需要自行编写</p>
    </div>
    <div class="section">
        <h3>第四屏</h3>
        <p>这是最后一屏</p>
    </div>
</div>

5.js部分

<script>
$(function(){
    $('#dowebok').fullpage({
    sectionsColor: ['#1bbc9b', '#4BBFC3', '#7BAABE', '#f90'],
    //设置颜色参数
    anchors: ['page1', 'page2', 'page3', 'page4'],
    //定义锚链接
    menu: '#menu'
    //绑定菜单,设定的相关属性与 anchors 的值对应后,菜单可以控制滚动
    });
});
</script>
$(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){}
    });
});

下面有中文版

controlArrows: (default true) Determines whether to use control arrows for the slides to move right or left.

verticalCentered: (default true) Vertically centering of the content within sections. When set to true, your content will be wrapped by the library. Consider using delegation or load your other scripts in the afterRender callback.

scrollingSpeed: (default 700) Speed in milliseconds for the scrolling transitions.

sectionsColor: (default none) Define the CSS background-color property for each section. Example:

$('#fullpage').fullpage({
    sectionsColor: ['#f2f2f2', '#4BBFC3', '#7BAABE', 'whitesmoke', '#000'],
});
anchors: (default []) Defines the anchor links (#example) to be shown on the URL for each section. Anchors value should be unique. The position of the anchors in the array will define to which sections the anchor is applied. (second position for second section and so on). Using anchors forward and backward navigation will also be possible through the browser. This option also allows users to bookmark a specific section or slide. Be careful! anchors can not have the same value as any ID element on the site (or NAME element for IE). Now anchors can be defined directly in the HTML structure by using the attribute data-anchor as explained here.

lockAnchors: (default false) Determines whether anchors in the URL will have any effect at all in the library. You can still using anchors internally for your own functions and callbacks, but they won't have any effect in the scrolling of the site. Useful if you want to combine fullPage.js with other plugins using anchor in the URL.

Important It is helpful to understand that the values in the anchors option array correlate directly to the element with the class of .section by it's position in the markup.

easing: (default easeInOutCubic) Defines the transition effect to use for the vertical and horizontal scrolling. It requires the file vendors/jquery.easings.min.js or jQuery UI for using some of its transitions. Other libraries could be used instead.

easingcss3: (default ease) Defines the transition effect to use in case of using css3:true. You can use the pre-defined ones (such as linear, ease-out...) or create your own ones using the cubic-bezier function. You might want to use Matthew Lein CSS Easing Animation Tool for it.

loopTop: (default false) Defines whether scrolling up in the first section should scroll to the last one or not.

loopBottom: (default false) Defines whether scrolling down in the last section should scroll to the first one or not.

loopHorizontal: (default true) Defines whether horizontal sliders will loop after reaching the last or previous slide or not.

css3: (default true). Defines whether to use JavaScript or CSS3 transforms to scroll within sections and slides. Useful to speed up the movement in tablet and mobile devices with browsers supporting CSS3. If this option is set to true and the browser doesn't support CSS3, a jQuery fallback will be used instead.

autoScrolling: (default true) Defines whether to use the "automatic" scrolling or the "normal" one. It also has affects the way the sections fit in the browser/device window in tablets and mobile phones.

fitToSection: (default true) Determines whether or not to fit sections to the viewport or not. When set to true the current active section will always fill the whole viewport. Otherwise the user will be free to stop in the middle of a section.

fitToSectionDelay: (default 1000). If fitToSection is set to true, this delays the fitting by the configured milliseconds.

scrollBar: (default false) Determines whether to use scrollbar for the site or not. In case of using scroll bar, the autoScrolling functionality will still work as expected. The user will also be free to scroll the site with the scroll bar and fullPage.js will fit the section in the screen when scrolling finishes.

paddingTop: (default 0) Defines the top padding for each section with a numerical value and its measure (paddingTop: '10px', paddingTop: '10em'...) Useful in case of using a fixed header.

paddingBottom: (default 0) Defines the bottom padding for each section with a numerical value and its measure (paddingBottom: '10px', paddingBottom: '10em'...). Useful in case of using a fixed footer.

fixedElements: (default null) Defines which elements will be taken off the scrolling structure of the plugin which is necessary when using the css3 option to keep them fixed. It requires a string with the jQuery selectors for those elements. (For example: fixedElements: '#element1, .element2')

normalScrollElements: (default null) If you want to avoid the auto scroll when scrolling over some elements, this is the option you need to use. (useful for maps, scrolling divs etc.) It requires a string with the jQuery selectors for those elements. (For example: normalScrollElements: '#element1, .element2'). This option should not be applied to any section/slide element itself.

normalScrollElementTouchThreshold : (default 5) Defines the threshold for the number of hops up the html node tree Fullpage will test to see if normalScrollElements is a match to allow scrolling functionality on divs on a touch device. (For example: normalScrollElementTouchThreshold: 3)

bigSectionsDestination: (default null) Defines how to scroll to a section which size is bigger than the viewport. By default fullPage.js scrolls to the top if you come from a section above the destination one and to the bottom if you come from a section below the destination one. Possible values are top, bottom, null.

keyboardScrolling: (default true) Defines if the content can be navigated using the keyboard.

touchSensitivity: (default 5) Defines a percentage of the browsers window width/height, and how far a swipe must measure for navigating to the next section / slide

continuousVertical: (default false) Defines whether scrolling down in the last section or should scroll down to the first one and if scrolling up in the first section should scroll up to the last one. Not compatible with loopTop, loopBottom or any scroll bar present in the site (scrollBar:true or autoScrolling:false).

continuousHorizontal: (default false) Extension of fullpage.js. Defines whether sliding right in the last slide should slide right to the first one or not, and if scrolling left in the first slide should slide left to the last one or not. Not compatible with loopHorizontal. Requires fullpage.js >= 2.8.3.

scrollHorizontally: (default false) Extension of fullpage.js. Defines whether to slide horizontally within sliders by using the mouse wheel or trackpad. Ideal for story telling. Requires fullpage.js >= 2.8.3.

interlockedSlides: (default false) Extension of fullpage.js. Determines whether moving one horizontal slider will force the sliding of sliders in other section in the same direction. Possible values are true, false or an array with the interlocked sections. For example [1,3,5] starting by 1. Requires fullpage.js >= 2.8.3.

dragAndMove: (default false) Extension of fullpage.js. Enables or disables the dragging and flicking of sections and slides by using mouse or fingers. Requires fullpage.js >= 2.8.9. Possible values are:

true: enables the feature.
false: disables the feature.
vertical: enables the feature only vertically.
horizontal: enables the feature only horizontally.
fingersonly: enables the feature for touch devices only.
mouseonly: enables the feature for desktop devices only (mouse and trackpad).
offsetSections: (default false)Extension of fullpage.js. Provides a way to use non full screen sections based on percentage. Ideal to show visitors there's more content in the site by showing part of the next or previous section. Requires fullPage.js >= 2.8.8 To define the percentage of each section the attribute data-percentage must be used. The centering of the section in the viewport can be determined by using a boolean value in the attribute data-centered (default to true if not specified). For example:

    <div class="section" data-percentage="80" data-centered="true">
resetSliders: (default false). Extension of fullpage.js. Defines whether or not to reset every slider after leaving its section. Requires fullpage.js >= 2.8.3.

fadingEffect: (default false). Extension of fullpage.js. Defines whether to use a fading effect or not instead of the default scrolling one. Possible values are true, false, sections, slides. It can therefore be applied just vertically or horizontally, or to both at the time. Requires fullpage.js >= 2.8.6.

animateAnchor: (default true) Defines whether the load of the site when given an anchor (#) will scroll with animation to its destination or will directly load on the given section.

recordHistory: (default true) Defines whether to push the state of the site to the browser's history. When set to true each section/slide of the site will act as a new page and the back and forward buttons of the browser will scroll the sections/slides to reach the previous or next state of the site. When set to false, the URL will keep changing but will have no effect on the browser's history. This option is automatically turned off when using autoScrolling:false.

menu: (default false) A selector can be used to specify the menu to link with the sections. This way the scrolling of the sections will activate the corresponding element in the menu using the class active. This won't generate a menu but will just add the active class to the element in the given menu with the corresponding anchor links. In order to link the elements of the menu with the sections, an HTML 5 data-tag (data-menuanchor) will be needed to use with the same anchor links as used within the sections. Example:

<ul id="myMenu">
    <li data-menuanchor="firstPage" class="active"><a href="#firstPage" rel="external nofollow" >First section</a></li>
    <li data-menuanchor="secondPage"><a href="#secondPage" rel="external nofollow" >Second section</a></li>
    <li data-menuanchor="thirdPage"><a href="#thirdPage" rel="external nofollow" >Third section</a></li>
    <li data-menuanchor="fourthPage"><a href="#fourthPage" rel="external nofollow" >Fourth section</a></li>
</ul>
$('#fullpage').fullpage({
    anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],
    menu: '#myMenu'
});
Note: the menu element should be placed outside the fullpage wrapper in order to avoid problem when using css3:true. Otherwise it will be appended to the body by the plugin itself.

navigation: (default false) If set to true, it will show a navigation bar made up of small circles.

navigationPosition: (default none) It can be set to left or right and defines which position the navigation bar will be shown (if using one).

navigationTooltips: (default []) Defines the tooltips to show for the navigation circles in case they are being used. Example: navigationTooltips: ['firstSlide', 'secondSlide']. You can also define them by using the attribute data-tooltip in each section if you prefer.

showActiveTooltip: (default false) Shows a persistent tooltip for the actively viewed section in the vertical navigation.

slidesNavigation: (default false) If set to true it will show a navigation bar made up of small circles for each landscape slider on the site.

slidesNavPosition: (default bottom) Defines the position for the landscape navigation bar for sliders. Admits top and bottom as values. You may want to modify the CSS styles to determine the distance from the top or bottom as well as any other style such as color.

scrollOverflow: (default false) (not compatible with IE 8) defines whether or not to create a scroll for the section/slide in case its content is bigger than the height of it. When set to true, your content will be wrapped by the plugin. Consider using delegation or load your other scripts in the afterRender callback. In case of setting it to true, it requires the vendor library scrolloverflow.min.js. This file has to be loaded before the fullPage.js plugin, but after jQuery. For example:

<script type="text/javascript" src="vendors/scrolloverflow.min.js"></script>
<script type="text/javascript" src="jquery.fullPage.js"></script>
In order to prevent fullpage.js from creating the scrollbar in certain sections or slides use the class fp-noscroll. For example: <div class="section fp-noscroll">

You can also prevent scrolloverflow from getting applied on responsive mode when using fp-auto-height-responsive in the section element.

scrollOverflowReset: (default false) Extension of fullpage.js. When set to true it scrolls up the content of the section/slide with scroll bar when leaving to another vertical section. This way the section/slide will always show the start of its content even when scrolling from a section under it.

scrollOverflowOptions: when using scrollOverflow:true fullpage.js will make use of a forked and modified version of iScroll.js library. You can customize the scrolling behaviour by providing fullpage.js with the iScroll.js options you want to use. Check its documentation for more info.

sectionSelector: (default .section) Defines the jQuery selector used for the plugin sections. It might need to be changed sometimes to avoid problem with other plugins using the same selectors as fullpage.js.

slideSelector: (default .slide) Defines the jQuery selector used for the plugin slides. It might need to be changed sometimes to avoid problem with other plugins using the same selectors as fullpage.js.

responsiveWidth: (default 0) A normal scroll (autoScrolling:false) will be used under the defined width in pixels. A class fp-responsive is added to the body tag in case the user wants to use it for his own responsive CSS. For example, if set to 900, whenever the browser's width is less than 900 the plugin will scroll like a normal site.

responsiveHeight: (default 0) A normal scroll (autoScrolling:false) will be used under the defined height in pixels. A class fp-responsive is added to the body tag in case the user wants to use it for his own responsive CSS. For example, if set to 900, whenever the browser's height is less than 900 the plugin will scroll like a normal site.

responsiveSlides: (default false) Extension of fullpage.js. When set to true slides will be turned into vertical sections when responsive mode is fired. (by using the responsiveWidth or responsiveHeight options detailed above). Requires fullpage.js >= 2.8.5.

parallax: (default false) Extension of fullpage.js. Defines whether or not to use the parallax backgrounds effects on sections / slides. Read more about how to apply the parallax option.

parallaxOptions: (default: { type: 'reveal', percentage: 62, property: 'translate'}). Allows to configure the parameters for the parallax backgrounds effect when using the option parallax:true. Read more about how to apply the parallax option.

lazyLoading: (default true) Lazy loading is active by default which means it will lazy load any media element containing the attribute data-src as detailed in the Lazy Loading docs . If you want to use any other lazy loading library you can disable this fullpage.js feature.

Methods
You can see them in action here

moveSectionUp()
Demo Scrolls one section up:

$.fn.fullpage.moveSectionUp();
moveSectionDown()
Demo Scrolls one section down:

$.fn.fullpage.moveSectionDown();
moveTo(section, slide)
Demo Scrolls the page to the given section and slide. The first slide, the visible one by default, will have index 0.

/*Scrolling to the section with the anchor link `firstSlide` and to the 2nd Slide */
$.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.

/*Scrolling to the section with the anchor link `firstSlide` and to the 2nd Slide */
$.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使用内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • 全屏滚动插件fullPage.js使用实例解析

    如今我们经常能看见到全屏网站,尤其是国外玩站.这些网站用几幅很大的图片或色块做背景,再添加一些简单的内容,显得格外的高端大气上档次.而JQuery的一款插件fullpage.js,可以实现全屏滚动,非常流行的效果,兼容性IE8+兼容性不错,能够兼容多种浏览器. 主要功能有: 支持鼠标滚动 支持前进后退和键盘控制 多个会调函数 支持手机.平板触摸事件 支持CSS3动画 支持窗口缩放 窗口缩放时自动调整 可设置滚动宽度.背景颜色.滚动速度.循环选项.回调.文本对齐方式等等 准备工作(下载jquery

  • fullPage.js和CSS3实现全屏滚动效果

    首先说一下fullpage,它是一个jquery的插件,用来实现鼠标向上向下滑动,就会自动切换到上一屏或者下一屏,对于要做一些高大上的效果确实是一个很好的插件.首先先展示一下基本的效果图. 总共有四屏的内容 当鼠标每次上下滑动时就会一整屏的切换. 第一屏是用一个图片,其他的三屏都是由左侧的三个图片和右侧的两个图片组成的. 这三屏左侧的图片展开方式不同,所以就更有炫酷的效果. 第二屏的三个图片是当页面显示时从下到上依次出来到正确的位置. 第三屏的三个图片是当页面显示时从左到右依次展开到正确的位置.

  • fullpage.js全屏滚动插件使用实例

    刚做好公司网站,通过全屏滚动,显著提高了官网的浏览体验.遂总结一下使用fullpage.js的方法.欢迎指正 一. fullpage.js简介 fullpage.js是一套实现浏览器全屏滚动的js插件,很多网站现在都使用了其来实现较好的浏览体验.  可以实现的功能: •支持前进后退和键盘控制  •多个回调函数  •支持手机.平板触摸事件  •支持 CSS3 动画  •支持窗口缩放  •窗口缩放时自动调整  •可设置滚动宽度.背景颜色.滚动速度.循环选项.回调.文本对齐方式等等 二.插件下载 np

  • fullpage.js最后一屏滚动方式

    这两天公司网页改版用到fullpage.js这个滚屏插件,页面内容整屏的滚动,不成问题,各种设置在网上也都有文档. 而我遇到的问题就是,页面内容不满屏的时候,和上面的内容放一块就太挤,单独放一屏就太空,好尴尬的说 底部的footer部分就是我要单独处理的部分,从网上搜了各种资料,总结了一下,个人觉着最简单的方法,写一篇文章以便以后查阅. <!--footer及倒数第二屏的HTML--> <body data-spy="scroll"> <div id=&q

  • Fullpage.js固定导航栏-实现定位导航栏

    FullPage.js 是一个简单而易于使用的插件,用来创建全屏滚动网站(也被称为单页网站).除了可以创建全屏滚动效果以外,也可以给网站添加一些水平的滑块效果.能够自适应不同的屏幕尺寸,包括平板电脑和移动设备. 开始制作自己的个人简历啦,决定要使用固定导航栏,又打算使用fullpage.js做全屏滚动. 仔细看了fullpage文档之后,发现不用额外写js代码就可以实现以下效果: 1.当滚动翻页时,导航栏也自动定位到这一页的标签 2.当然点击标签时,也是滚动到那一页而不是直接跳转的. 一.准备工

  • fullpage.js全屏滚动的具体使用方法

    1.fullpage.js  下载地址 https://github.com/alvarotrigo/fullPage.js 2.fullPage.js 是一个基于 jQuery 的插件,它能够很方便.很轻松的制作出全屏网站,主要功能有: 支持鼠标滚动 支持前进后退和键盘控制 多个回调函数 支持手机.平板触摸事件 支持 CSS3 动画 支持窗口缩放 窗口缩放时自动调整 可设置滚动宽度.背景颜色.滚动速度.循环选项.回调.文本对齐方式等等 3.在相应的HTML页面中引入一下文件 <link rel

  • 微信小程序全屏滚动字幕的实现方法详解

    目录 一.实现背景 二.实现代码 三.滚动速度 四.后续优化 实现效果 一.实现背景 无意中在某音上看到用手机横屏作为广告屏的视频,大部分都是用第三方软件实现的: 以及在汽车后挡风玻璃放置提醒字样的视频,这种基本是要花钱买屏幕,通过手机控制屏幕内容: 遂想实现这种效果 二.实现代码 1,滚动字幕 zimu.wxml,界面布局,很简单,没啥特别的,顶部一个返回按钮,为了不影响整体效果,可以把这个按钮做成透明的图片放上去:除了那个按钮剩下的就是滚动的字幕组件了 <!--pages/zimu/zimu

  • Javascript 实现全屏滚动实例代码

    JS 全屏滚动 参照fullPage.js的效果,用自己的想法实现的. 实现的效果:1.全屏滚动,滚动一下齿轮就会滚动全屏. 2.自适应缩放,无论怎么改变窗口的大小,都会保证用一个元素占满全屏. 下一步计划: 1.改成react组件 2.实现更多的效果 注释写的很清楚,基本上知道函数怎么用就可以了.有想法这东西就很简单. 这里偷懒使用了我之前写过的一个运动框架(其实就是一个函数),稍加修改就可以在这上面使用.框架相关:点击这里 注释非常详细了,就不说其他的了.直接上代码: <!DOCTYPE h

  • 用ES6写全屏滚动插件的示例代码

    这篇文章将介绍如何使用原生 JS (主要使用 ES6 语法)实现全屏滚动插件,兼容 IE 10+.手机触屏,Mac 触摸板优化,支持自定义页面动画,压缩后 gzip 文件只有 2k.完整源码在这 pure_full_page,点这查看demo. 1)前面的话 现在已经有很多全屏滚动插件了,比如著名的 fullPage ,那为什么还要自己造轮子呢? 现有轮子有以下问题: 首先,最大的问题是最流行的几个插件都依赖 jQuery,这意味着在使用 React 或者 Vue 的项目中使用他们是一件十分蛋疼

  • jQuery插件fullPage.js实现全屏滚动效果

    本文实例为大家分享了全屏滚动插件fullPage.js的具体使用方法,供大家参考,具体内容如下 0.01 基本演示  的HTML 布局 以及js 代码 //需要连接 连接的三个文件 <link rel="stylesheet" href="css/jquery.fullPage.css"> //css文件 <script src="js/jquery-1.8.3.min.js"></script> //jQue

  • 原生js实现类似fullpage的单页/全屏滚动

    前言 单页/全屏滚动页面越来越常见了,它多用于产品介绍.招聘等内容较少的简单页面.针对这种效果也出现了不少 jQuery 插件,本文实现的效果类似于fullpage的单屏滚动,使用原生JS实现,不依赖任何js库: css代码: html,body {height:100%;} body {margin:0px;} div {height:100%;} html代码: <div style="background:#FEE;"></div> <div sty

  • vue实现全屏滚动效果(非fullpage.js)

    本文实例为大家分享了vue实现全屏滚动效果(的具体代码,供大家参考,具体内容如下 是什么 网页的一个页面占据一屏的宽高,多个页面上下或者左右拼接在一起.当滑动鼠标滚轮,或点击导航按钮时,可以平滑到对应的页面. 此次只实现鼠标滚动 实现原理 使用mousewheel , DOMMouseScroll(火狐用)监听鼠标滚动事件,当鼠标上下的滚动的时候,当前的页面transformY(屏高)或者transformX(屏宽) 代码实现 HTML <template> <div class=&qu

随机推荐