简体   繁体   English

在我的非画布菜单上添加滑动功能

[英]Add swipe function on my off-canvas menu

I have a off canvas menu on my mobile HTML site. 我的移动HTML网站上有一个关闭画布的菜单。

DEMO DEMO

Its working good but slide effect working on just toggle-button. 它的工作效果很好,但滑动效果仅在切换按钮上起作用。 But I need swipe function on the menu. 但是我需要菜单上的滑动功能。 How can I add it? 如何添加?

JS: JS:

$(function() {

    // Toggle Nav on Click
    $('.toggle-nav').click(function() {
        // Calling a function in case you want to expand upon this.
        toggleNav();
    });


});

function toggleNav() {
    if ($('#site-wrapper').hasClass('show-nav')) {
        // Do things on Nav Close
        $('#site-wrapper').removeClass('show-nav');
    } else {
        // Do things on Nav Open
        $('#site-wrapper').addClass('show-nav');
    }

}

Since you're using jQuery you can take advantage of the jQuery swipe event handler. 由于您使用的是jQuery,因此可以利用jQuery swipe事件处理程序。

$(window).on("swipe", function(event){ ... }) . $(window).on("swipe", function(event){ ... })

Docs here. 文档在这里。

Simply listen to the swipe event 只需聆听swipe事件

$("#site-canvas").on("swipe", function() {
    toggleNav();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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