1

I'm using the fullpage.js plugin for a single page marketing site.

I'm using navigation links to jump to scenes (all horizontal) around the site so I want to disable to the touch/swipe (between scenes) feature as it interferes with other touch elements.

I've been though all the documentation but I can't find out how to achieve this.

Any help is welcome. Thanks, Jack.

Jack Barham
  • 3,197
  • 10
  • 41
  • 62

3 Answers3

5

Just use the option autoScrolling:false when initializing the plugin. This way the mouse wheel won't swipe and neither the touch events will.

If you want to keep the mouse wheel scrolling (for computers) but disable the touch events (touch devices), then I would recommend you to initialize the plugin in a different way for touch devices. In order to do so, I recommend you to do something like this.

Update 2016:

You can use the options responsiveWidth or responsiveHeight as well as the class fp-auto-height-responsive.

The options will disable the autoScrolling feature for mobile devices under the specified dimensions. Examples available in the examples folder of fullPage.js or online.

You can also use responsiveSlides and force the transformation of horizontal slides into vertical sections on responsive. This can be done through the Responsive Slides extension.

Update Sep-2014:


A method named $.fn.fullpage.setAllowScrolling can also be used with this same purpose. It will disable both the touch scrolling and the mouse scrolling.


Update Jun-2014:


autoScrolling:false only disables the vertical scrolling. If you want also to disable the horizontal one, there's no way to do it right now. You would need to modify a bit the plugin.

Inside fullpage.js replaces this:

function removeTouchHandler() {
    if (isTablet) {
        $(document).off('touchstart MSPointerDown');
        $(document).off('touchmove MSPointerMove');
    }
}

For this:

$.fn.fullpage.removeTouchHandler = function (){ 
    if (isTablet) {
        $(document).off('touchstart MSPointerDown');
        $(document).off('touchmove MSPointerMove');
    }
};

And then, when you initialize the plugin, call that public function in the afterRender callback like so:

$(document).ready(function() {
    $('#fullpage').fullpage({
        afterRender: function(){
            $.fn.fullpage.removeTouchHandler();
        }
    });
});

Don't call fullpage twice. Just add the afterRender function inside your initialization.

Community
  • 1
  • 1
Alvaro
  • 40,778
  • 30
  • 164
  • 336
  • Thank you for getting back to me. I've tried "autoScrolling:false" and it doesn't work - I think it just stops the page from automatically scrolling once the DOM is loaded. I'm looking for something that will stop left/right swiping on touch devices so each scene is only accessible though a custom menu (anchor points). – Jack Barham Jun 03 '14 at 13:04
  • @JackBarham right. I've updated my answer. Please check it out. – Alvaro Jun 03 '14 at 13:42
  • Thanks for making the update. I've updated the files as you have suggested above and now it doesn't slide when I click on any of the anchor points. – Jack Barham Jun 03 '14 at 14:37
  • @JackBarham can you post your URL? That would make it easier for me to see the problem. Do you get any console error? – Alvaro Jun 03 '14 at 16:00
  • Sure, it's very much work in progress, but here you go: http://airboxmedia.com/clients/jeep/ – Jack Barham Jun 04 '14 at 08:42
  • @JackBarham it slides correctly for me when clicking on the menu on my computer... – Alvaro Jun 04 '14 at 09:25
  • @JackBarham but i see it still scrolling when touching it in the phone. I also saw you didn't update your initialization as I said... I can not see the `removeTouchHandler` in [your initialization](http://airboxmedia.com/clients/jeep/library/js/local/scripts-min.js)... – Alvaro Jun 04 '14 at 09:27
  • I want to DISABLE the left/right touch swipe. The aim is to get to each scene via the menu at the bottom only and not through swiping left/right. This is because when an item is touched it can accidentally slide to the next/previous scene if the user is a little heavy handed. Hope that makes sense. – Jack Barham Jun 04 '14 at 09:31
  • I did have it in but took it out because it completely disabled the bottom navigation. – Jack Barham Jun 04 '14 at 09:33
  • @JackBarham I know what you want. Can you please update your initialization of the plugin following the steps I told you? You didn't change what I said in the last comment... – Alvaro Jun 04 '14 at 09:41
  • If you look at the console you will see an error. That's because in fullpage.js file you also need to replace the old call of `removeTouchHandler();` for the new one `$.fn.fullpage.removeTouchHandler();` inside the `setAllowScrolling` function. – Alvaro Jun 04 '14 at 09:55
  • I've made those updates and I'm still getting errors. Apologise about this, I'm still learning JS. – Jack Barham Jun 04 '14 at 10:04
  • 1
    Move the `$.fn.fullpage.removeTouchHandler = function (){ ` function at the top of the fullpage.js file, just before the `setMouseWheelScrolling ` function. – Alvaro Jun 04 '14 at 10:42
  • ITS WORKED!!! Didn't think to change the order. Thanks for all your help on this. I'm going to remove the dev link shortly, due to the fact its a large client and its still in production. But I will send you a link when its finished. I've used your script on other projects and always really liked it. – Jack Barham Jun 04 '14 at 10:54
2

The setAllowScrolling function also accepts a second argument for directions so the following can be used to disable left/right scrolling/swiping:

$.fn.fullpage.setAllowScrolling(false, 'left, right');

0

As of June 2017, none of the previous methods worked for me. The simplest way I found to effectively disable touch is as follows.

In jquery.fullPage.js you will find the function setAllowScrolling

function setAllowScrolling(value, directions){
    if(typeof directions !== 'undefined'){
        directions = directions.replace(/ /g,'').split(',');

        $.each(directions, function (index, direction){
            setIsScrollAllowed(value, direction, 'm');
        });
    }
    else if(value){
        setMouseWheelScrolling(true);
        addTouchHandler();
    }else{
        setMouseWheelScrolling(false);
        removeTouchHandler();
    }
}

When fullpage is initialized it automatically calls setAllowScrolling(true), triggering the else if(value) condition above. Simply comment out the call to addTouchHandler() to fully disable it, or add some sort of condition for it to be called, eg

var winw = $(window).width();
if (winw > 480){
    addTouchHandler();
} 

With this method the left and right arrows still work when tapped, so horizontal slides can still be navigated. It should be noted that using $.fn.fullpage.setAllowScrolling(false, 'left, right'); will also disable the arrows.

AFOC
  • 699
  • 6
  • 15
  • Not a good idea to modify the library... Why wouldn't the responsive mode work for you? – Alvaro Jun 09 '17 at 09:30
  • @Alvaro The responsive mode does work nicely, but the swipe gestures are way too sensitive on a small device. I have it so it's vertically scrolling like a normal long page, but horizontal is still controlled as slides. When scrolling up/down the slides jump left and right all over the place and I didn't find a simple way to disable that outside of modifying the library in this small way. – AFOC Jun 09 '17 at 16:24
  • You can adjust that by using the optioon `touchSensitivity`. – Alvaro Jun 09 '17 at 21:48
  • Wow can't believe I missed that option. Thanks. So would `touchSensitivity:0` disable the swiping completely then? – AFOC Jun 10 '17 at 04:17
  • Just use `setAllowScrolling` to disable it. – Alvaro Jun 10 '17 at 20:42
  • I tried calling `setAllowScrolling` with no parameters which should trigger `removeTouchHandler`, however it does not disable the swiping, it does not seem like it works at all. The only method I could find to ensure it was completely disabled was to prevent it from being set to begin with. – AFOC Jun 11 '17 at 17:53
  • If you use `setAllowScrolling(false)` it will definetely call `removeTouchHandler` as you can see [in the source code](https://github.com/alvarotrigo/fullPage.js/blob/master/jquery.fullPage.js#L340). – Alvaro Jun 12 '17 at 09:58