Disable fullpage.js on mobile (touch) devices

时光怂恿深爱的人放手 提交于 2019-12-09 11:31:10

问题


I'm using fullpage.js and the slimscroll.js plugin, which is required to allow scrolling in a section which has content that exceeds the height it's container section.

I've noticed that the experience is quite bad on touch devices. Whereas normally you can swipe, release and watch the page still scroll, on a slimscroll div as soon as your finger leaves the touch area, the scrolling stops.

So what I'd like to do is disable fullpage.js on mobiles and tablets, but still enable it on desktops. I checked out fullPage.js's issues and documentation but I couldn't find a simple way of doing this.

Could anyone help me out?

Thanks a lot


回答1:


Just don't initialize fullpage on touch devices. You will have to deal with the mobile/touch devices detection. Just search a bit on google or even here to find different alternatives.

It should look like this:

var isPhoneDevice = [ WHATEVER FUNCTION YOU WANT TO USE ]

//if it is not a phone device...
if(!isPhoneDevice){
    //initializing fullpage...
    $.fn.fullpage();
}

UPDATE

At the moment fullpage.js provides another alternative. Using the responsiveWidth and responsiveHeight options. This way fullpage.js will act as a normal website under the given values (in px).

This can also be combined with the class fp-auto-height-responsive in order to prevent fullPage.js to set the sections height on responsive and let you total control over them.

More in the docs.




回答2:


I use this way!

var isPhoneDevice = "ontouchstart" in document.documentElement; 
$(document).ready(function() {
        if(isPhoneDevice){
            //mobile
        }
            else{
                //desktop               
                $.fn.fullpage();
            }
        });



回答3:


Even easier way that I came across here on Stackexchange - this is what I'm using:

if(screen.width < 480) { 
// do any 480 width stuff here, or simply do nothing
return;
} else {
// do all your cool stuff here for larger screens
}



回答4:


Responsive design possibilities have been added to fullPage.js since last answer. You can seen example by the following link.

Read about responsiveWidth and responsiveHeight in documentation for details.



来源:https://stackoverflow.com/questions/22457529/disable-fullpage-js-on-mobile-touch-devices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!