alvarotrigo / fullPage.js

fullPage plugin by Alvaro Trigo. Create full screen pages fast and simple
http://alvarotrigo.com/fullPage/
GNU General Public License v3.0
35.04k stars 7.3k forks source link
fullpage fullscreen javascript jquery mousewheel onepage scrolling sections slide slideshow snap swipe

fullPage.js

preview compatibility

English | Español | Français | Pусский | 中文 | 한국어 | Português Brasileiro

Available for Vue, React and Angular.


fullPage.js version License PayPal Donate jsDelivr Hits Minzipped Size   |   Created by @imac2

A simple and easy to use library that creates fullscreen scrolling websites (also known as single page websites or onepage sites) and adds landscape sliders inside the sections of the site.

Introduction

Suggestion are more than welcome, not only for feature requests but also for coding style improvements. Let's make this a great library to make people's lives easier!

Compatibility

fullPage.js is fully functional on all modern browsers and with IE 11. If you need to support IE < 11 consider using fullPage.js v3. It also provides touch support for mobile phones, tablets and touch screen computers.

Special thanks to Browserstack for supporting fullpage.js.

License

Commercial license

If you want to use fullPage to develop non open sourced sites, themes, projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Which means, you won't have to change your whole application source code to an open source license. [Purchase a Fullpage Commercial License]

Open source license

If you are creating an open source application under a license compatible with the GNU GPL license v3, you may use fullPage under the terms of the GPLv3.

You will have to provide a prominent notice that fullPage.js is in use. The credit comments in the JavaScript and CSS files should be kept intact (even after combination or minification).

Read more about fullPage's license.

Usage

As you can see in the example files, you will need to include:

Install using bower or npm

Optionally, you can install fullPage.js with bower or npm if you prefer:

Terminal:

// With bower
bower install fullpage.js

// With npm
npm install fullpage.js

Including files:

<link rel="stylesheet" type="text/css" href="https://github.com/alvarotrigo/fullPage.js/blob/master/fullpage.css" />

<!-- This following line is optional. Only necessary if you use the option css3:false and you want to use other easing effects rather than "easeInOutCubic". -->
<script src="https://github.com/alvarotrigo/fullPage.js/raw/master/vendors/easings.min.js"></script>

<script type="text/javascript" src="https://github.com/alvarotrigo/fullPage.js/raw/master/fullpage.js"></script>

Using Webpack, Browserify or Require.js? Check how to use fullPage.js with module loaders.

Optional use of CDN

If you prefer to use a CDN to load the needed files, fullPage.js is in CDNJS: https://cdnjs.com/libraries/fullPage.js

Required HTML structure

Start your HTML document with the compulsory HTML DOCTYPE declaration on the 1st line of your HTML code. You might have troubles with sections heights otherwise. The examples provided use HTML 5 doctype <!DOCTYPE html>.

Each section will be defined with an element containing the section class. The active section by default will be the first section, which is taken as the home page.

Sections should be placed inside a wrapper (<div id="fullpage"> in this case). The wrapper can not be the body element.

<div id="fullpage">
    <div class="section">Some section</div>
    <div class="section">Some section</div>
    <div class="section">Some section</div>
    <div class="section">Some section</div>
</div>

If you want to define a different starting point rather than the first section or the first slide of a section, just add the class active to the section and slide you want to load first.

<div class="section active">Some section</div>

In order to create a landscape slider within a section, each slide will be defined by default with an element containing the slide class:

<div class="section">
    <div class="slide"> Slide 1 </div>
    <div class="slide"> Slide 2 </div>
    <div class="slide"> Slide 3 </div>
    <div class="slide"> Slide 4 </div>
</div>

You can see a fully working example of the HTML structure in the simple.html file.

Initialization

Initialization with Vanilla Javascript

All you need to do is call fullPage.js before the closing </body> tag.

new fullpage('#fullpage', {
    //options here
    autoScrolling:true,
    scrollHorizontally: true
});

Initialization with jQuery

You can use fullpage.js as a jQuery plugin if you want to!

$(document).ready(function() {
    $('#fullpage').fullpage({
        //options here
        autoScrolling:true,
        scrollHorizontally: true
    });

    //methods
    $.fn.fullpage.setAllowScrolling(false);
});

Functions and methods can still be called in the jQuery way, as in fullPage.js v2.X.

Vanilla JS example with all options

A more complex initialization with all options set could look like this:


var myFullpage = new 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: 600,
    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: true,
    scrollOverflowMacStyle: false,
    scrollOverflowReset: false,
    touchSensitivity: 15,
    bigSectionsDestination: null,

    // Accessibility
    keyboardScrolling: true,
    animateAnchor: true,
    recordHistory: true,

    // Design
    controlArrows: true,
    controlArrowsHTML: [
        '<div class="fp-arrow"></div>', 
        '<div class="fp-arrow"></div>'
    ],
    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'},
    dropEffect: false,
    dropEffectOptions: { speed: 2300, color: '#F82F4D', zIndex: 9999},
    waterEffect: false,
    waterEffectOptions: { animateContent: true, animateOnMouseMove: true},
    cards: false,
    cardsOptions: {perspective: 100, fadeContent: true, fadeBackground: true},

    // Custom selectors
    sectionSelector: '.section',
    slideSelector: '.slide',

    lazyLoading: true,
    observer: true,
    credits: { enabled: true, label: 'Made with fullPage.js', position: 'right'},

    // Events
    beforeLeave: function(origin, destination, direction, trigger){},
    onLeave: function(origin, destination, direction, trigger){},
    afterLoad: function(origin, destination, direction, trigger){},
    afterRender: function(){},
    afterResize: function(width, height){},
    afterReBuild: function(){},
    afterResponsive: function(isResponsive){},
    afterSlideLoad: function(section, origin, destination, direction, trigger){},
    onSlideLeave: function(section, origin, destination, direction, trigger){},
    onScrollOverflow: function(section, slide, position, direction){}
});

Creating links to sections or slides

If you are using fullPage.js with anchor links for the sections (using the anchors option or the attribute data-anchor in each section), then you will be able to use anchor links also to navigate directly to a certain slide inside a section.

This would be an example of a link with an anchor: https://alvarotrigo.com/fullPage/#secondPage/2 (which is the URL you will see once you access to that section/slide manually) Notice the last part of the URL ends in #secondPage/2.

Having the following initialization:

new fullpage('#fullpage', {
    anchors:['firstPage', 'secondPage', 'thirdPage']
});

The anchor at the end of the URL #secondPage/2 defines the section and slide of destination respectively. In the previous URL, the section of destination will be the one defined with the anchor secondPage and the slide will be the 2nd slide, as we are using the index 2 for it. (the fist slide of a section has index 0, as technically it is a section).

We could have used a custom anchor for the slide instead of its index if we would have used the attribute data-anchor on the HTML markup like so:

<div class="section">
    <div class="slide" data-anchor="slide1"> Slide 1 </div>
    <div class="slide" data-anchor="slide2"> Slide 2 </div>
    <div class="slide" data-anchor="slide3"> Slide 3 </div>
    <div class="slide" data-anchor="slide4"> Slide 4 </div>
</div>

In this last case, the URL we would use would be #secondPage/slide3, which is the equivalent to our previous #secondPage/2.

Note that section anchors can also be defined in the same way, by using the data-anchor attribute, if no anchors array is provided.

Be careful! data-anchor tags can not have the same value as any ID element on the site (or NAME element for IE).

Creating smaller or bigger sections

Demo fullPage.js provides a way to remove the full height restriction from its sections and slides. It is possible to create sections which height is smaller or bigger than the viewport. This is ideal for footers. It is important to realise that it doesn't make sense to have all of your sections using this feature. If there is more than one section in the initial load of the site, fullPage.js won't scroll at all to see the next one as it will be already in the viewport.

To create smaller sections just use the class fp-auto-height in the section you want to apply it. It will then take the height defined by your section/slide content.

<div class="section">Whole viewport</div>
<div class="section fp-auto-height">Auto height</div>

Responsive auto height sections

Demo A responsive auto height can be applied by using the class fp-auto-height-responsive. This way sections will be fullscreen until the responsive mode gets fired. Then they'll take the size required by their content, which could be bigger or smaller than the viewport.

State classes added by fullpage.js

Fullpage.js adds multiple classes in different elements to keep a record of the status of the site:

Lazy Loading

Demo fullPage.js provides a way to lazy load images, videos and audio elements so they won't slow down the loading of your site or unnecessarily waste data transfer. When using lazy loading, all these elements will only get loaded when entering in the viewport. To enable lazy loading all you need to do is change your src attribute to data-src as shown below:

<img data-src="https://github.com/alvarotrigo/fullPage.js/raw/master/image.png">
<video>
    <source data-src="https://github.com/alvarotrigo/fullPage.js/raw/master/video.webm" type="video/webm" />
    <source data-src="https://github.com/alvarotrigo/fullPage.js/raw/master/video.mp4" type="video/mp4" />
</video>

If you already use another lazy load solution which uses data-src as well, you can disable the fullPage.js lazy loading by setting the option lazyLoading: false.

Auto play/pause embedded media

Demo Note: the autoplay feature might not work on some mobile devices depending on the OS and browser (i.e. Safari on iOS version < 10.0).

Play on section/slide load:

Using the attribute autoplay for videos or audio, or the param autoplay=1 for youtube iframes will result in the media element playing on page load. In order to play it on section/slide load use instead the attribute data-autoplay. For example:

<audio data-autoplay>
    <source src="https://www.w3schools.com/html/horse.ogg" type="audio/ogg">
</audio>

Pause on leave

Embedded HTML5 <video> / <audio> and Youtube iframes are automatically paused when you navigate away from a section or slide. This can be disabled by using the attribute data-keepplaying. For example:

<audio data-keepplaying>
    <source src="https://www.w3schools.com/html/horse.ogg" type="audio/ogg">
</audio>

Use extensions

fullpage.js provides a set of extensions you can use to enhance its default features. All of them are listed as fullpage.js options.

Extensions requires you to use the minified file fullpage.extensions.min.js that is inside the dist folder instead of the usual fullPage.js file (fullpage.js or fullpage.min.js).

Once you acquire the extension file, you will need to add it before fullPage. For example, if I want to use the Continuous Horizontal extension, I would have include the extension file and then the extensions version of the fullPage file.

<script type="text/javascript" src="https://github.com/alvarotrigo/fullPage.js/raw/master/fullpage.continuousHorizontal.min.js"></script>
<script type="text/javascript" src="https://github.com/alvarotrigo/fullPage.js/raw/master/fullpage/fullpage.extensions.min.js"></script>

An activation key and a license key will be required for each extension. See more details about it here.

Then you will be able to use and configure them as explained in options.

Options

Methods

You can see them in action here

getActiveSection()

Demo Gets an Object (type Section) containing the active section and its properties.

fullpage_api.getActiveSection();

getActiveSlide()

Demo Gets an Object (type Slide) containing the active slide and its properties.

fullpage_api.getActiveSlide();

getScrollY() & getScrollX

Demo getScrollY Gets the Y position of the fullPage wrapper. getScrollX gets the X position of the active horizontal slide.

fullpage_api.getScrollY();
fullpage_api.getScrollX();

moveSectionUp()

Demo Scrolls one section up:

fullpage_api.moveSectionUp();

moveSectionDown()

Demo Scrolls one section down:

fullpage_api.moveSectionDown();

moveTo(section, slide)

Demo Scrolls the page to the given section and slide. The first section will have the index 1 whilst 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 */
fullpage_api.moveTo('firstSlide', 2);
//Scrolling to the 3rd section (with index 3) in the site
fullpage_api.moveTo(3, 0);

//Which is the same as
fullpage_api.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 */
fullpage_api.silentMoveTo('firstSlide', 2);

moveSlideRight()

Demo Scrolls the horizontal slider of the current section to the next slide:

fullpage_api.moveSlideRight();

moveSlideLeft()

Demo Scrolls the horizontal slider of the current section to the previous slide:

fullpage_api.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.

fullpage_api.setAutoScrolling(false);

setFitToSection(boolean)

Demo Sets the value for the option fitToSection determining whether to fit the section in the screen or not.

fullpage_api.setFitToSection(false);

fitToSection()

Demo Scrolls to the nearest active section fitting it in the viewport.

fullpage_api.fitToSection();

setLockAnchors(boolean)

Demo Sets the value for the option lockAnchors determining whether anchors will have any effect in the URL or not.

fullpage_api.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.


//disabling scrolling
fullpage_api.setAllowScrolling(false);

//disabling scrolling down
fullpage_api.setAllowScrolling(false, 'down');

//disabling scrolling down and right
fullpage_api.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).

//disabling all keyboard scrolling
fullpage_api.setKeyboardScrolling(false);

//disabling keyboard scrolling down
fullpage_api.setKeyboardScrolling(false, 'down');

//disabling keyboard scrolling down and right
fullpage_api.setKeyboardScrolling(false, 'down, right');

setRecordHistory(boolean)

Demo Defines whether to record the history for each hash change in the URL.

fullpage_api.setRecordHistory(false);

setScrollingSpeed(milliseconds)

Demo Defines the scrolling speed in milliseconds.

fullpage_api.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.

//destroying all Javascript events created by fullPage.js (scrolls, hashchange in the URL...)
fullpage_api.destroy();

//destroying all Javascript events and any modification done by fullPage.js over your original HTML markup.
fullpage_api.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.

fullpage_api.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.

fullpage_api.setResponsive(true);

responsiveSlides.toSections()

Extension of fullpage.js. Requires fullpage.js >= 3.0.1. Turns horizontal slides into vertical sections.

fullpage_api.responsiveSlides.toSections();

responsiveSlides.toSlides()

Extension of fullpage.js. Requires fullpage.js >= 3.0.1. Turns back the original slides (now converted into vertical sections) into horizontal slides again.

fullpage_api.responsiveSlides.toSlides();

Callbacks

Demo You can see them in action here.

Some callbacks, such as onLeave will contain Object type of parameters containing the following properties:

afterLoad (origin, destination, direction, trigger)

Demo Callback fired once the sections have been loaded, after the scrolling has ended. Parameters:

Example:

new fullpage('#fullpage', {
    anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],

    afterLoad: function(origin, destination, direction, trigger){
        var origin = this;

        //using index
        if(origin.index == 2){
            alert("Section 3 ended loading");
        }

        //using anchorLink
        if(origin.anchor == 'secondSlide'){
            alert("Section 2 ended loading");
        }
    }
});

onLeave (origin, destination, direction, trigger)

Demo 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:

Example:

new fullpage('#fullpage', {
    onLeave: function(origin, destination, direction, trigger){
        var leavingSection = this;

        //after leaving section 2
        if(origin.index == 1 && direction =='down'){
            alert("Going to section 3!");
        }

        else if(origin.index == 1 && direction == 'up'){
            alert("Going to section 1!");
        }
    }
});

beforeLeave (origin, destination, direction, trigger)

Demo This callback is fired right before leaving the section, just before the transition takes place.

You can use this callback to prevent and cancel the scroll before it takes place by returning false.

Parameters:

Example:


var cont = 0;
new fullpage('#fullpage', {
    beforeLeave: function(origin, destination, direction, trigger){

        // prevents scroll until we scroll 4 times
        cont++;
        return cont === 4;
    }
});

afterRender()

Demo 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:

new fullpage('#fullpage', {
    afterRender: function(){
        var pluginContainer = this;
        alert("The resulting DOM structure is ready");
    }
});

afterResize(width, height)

Demo This callback is fired after resizing the browser's window. Just after the sections are resized.

Parameters:

Example:

new fullpage('#fullpage', {
    afterResize: function(width, height){
        var fullpageContainer = this;
        alert("The sections have finished resizing");
    }
});

afterReBuild()

Demo This callback is fired after manually re-building fullpage.js by calling fullpage_api.reBuild().

Example:

new fullpage('#fullpage', {
    afterReBuild: function(){
        console.log("fullPage.js has manually being re-builded");
    }
});

afterResponsive(isResponsive)

Demo This callback is fired after fullpage.js changes from normal to responsive mode or from responsive mode to normal mode.

Parameters:

Example:

new fullpage('#fullpage', {
    afterResponsive: function(isResponsive){
        alert("Is responsive: " + isResponsive);
    }
});

afterSlideLoad (section, origin, destination, direction, trigger)

Demo Callback fired once the slide of a section have been loaded, after the scrolling has ended.

Parameters:

Example:

new fullpage('#fullpage', {
    anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],

    afterSlideLoad: function( section, origin, destination, direction, trigger){
        var loadedSlide = this;

        //first slide of the second section
        if(section.anchor == 'secondPage' && destination.index == 1){
            alert("First slide loaded");
        }

        //second slide of the second section (supposing #secondSlide is the
        //anchor for the second slide)
        if(section.index == 1 && destination.anchor == 'secondSlide'){
            alert("Second slide loaded");
        }
    }
});

onSlideLeave (section, origin, destination, direction, trigger)

Demo 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:

Example:

new fullpage('#fullpage', {
    onSlideLeave: function( section, origin, destination, direction, trigger){
        var leavingSlide = this;

        //leaving the first slide of the 2nd Section to the right
        if(section.index == 1 && origin.index == 0 && direction == 'right'){
            alert("Leaving the fist slide!!");
        }

        //leaving the 3rd slide of the 2nd Section to the left
        if(section.index == 1 && origin.index == 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.


onScrollOverflow (section, slide, position, direction)

Demo This callback gets fired when a scrolling inside a scrollable section when using the fullPage.js option scrollOverflow: true.

Parameters:

Example:

new fullpage('#fullpage', {
    onScrollOverflow: function( section, slide, position, direction){
        console.log(section);
        console.log("position: " + position);
    }
});

Reporting issues

  1. Please, look for your issue before asking using the github issues search.
  2. Make sure you use the latest fullpage.js version. No support is provided for older versions.
  3. Use the the Github Issues forum to create issues.
  4. An isolated reproduction of the issue will be required. Make use of jsfiddle or codepen for it if possible.

Contributing to fullpage.js

Please see Contributing to fullpage.js

Changelog

To see the list of recent changes, see Releases section.

Build tasks

Want to build fullpage.js distribution files? Please see Build Tasks

Resources

Who is using fullPage.js

Google Coca-cola eBay BBC Sony

Vodafone British Airways McDonalds EA Vogue Mi

Mercedes sym Bugatti eDarling Ubisoft

Donations

Donations would be more than welcome :)

Donate

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor] | [Become a patreon]

Codeless Stackpath Browserstack CodePen

People