简体   繁体   中英

jQuery mobile - allow only vertical scrolling when side panel is opened?

Referencing this I want to allow only vertical scroll.

The following code will disable all touch moves on a panel.

$(document).on("pageinit", "#form1", function (event) {
    $("#navmenu").on("panelopen", function (event, ui) {
        $("body").css("overflow", "hidden").on("touchmove", stopScroll);
    });
    $("#navmenu").on("panelclose", function (event, ui) {
        $("body").css("overflow", "auto").off("touchmove");
    });

    function stopScroll() {
        return false;
    }
});

How can I use "overflow-x: hidden" with the stopScroll function to allow vertical scroll and disable horizontal?

Thanks.

Have you tried like this

$("html, body").css("overflowX", "hidden");

Better make a css separate for mobile.

$(document).on('panelopen', '[data-role="panel"]',function (event) {
    document.ontouchmove = function(e) {
        e.preventDefault();
    }
}).on('panelclose', '[data-role="panel"]', function (event) {
        document.ontouchmove = function(e) {
             return true;
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM