从其他.js运行java事件

时间:2017-05-25 14:26:50

标签: javascript jquery

我有2个脚本。将它们分开工作完美,一个打开/关闭菜单,第二个识别滑动。但是如何在滑动动作/

上打开菜单

垂直菜单(点击按钮时显示和关闭菜单)

$(document).ready(function () {
  var trigger = $('.hamburger'),
      overlay = $('.overlay'),
      isClosed = false;

    $(".hamb-button").click(function () {
      hamburger_cross();
      $('#wrapper').toggleClass('toggled');      
    });

 function hamburger_cross() {

      if (isClosed == true) {          
        overlay.hide();
        trigger.removeClass('is-open');
        trigger.addClass('is-closed');
        isClosed = false;
      } else {   
        overlay.show();
        trigger.removeClass('is-closed');
        trigger.addClass('is-open');
        isClosed = true;
      }
  }

  $('[data-toggle="offcanvas"]').click(function () {
        $('#wrapper').toggleClass('toggled');
  });  
});

滑动脚本查找滑动事件

$(function() {      
  //Enable swiping...
  $(".swiper-slide").swipe({allowPageScroll:"auto"});
  $(".swiper-slide").swipe( { 
    //Generic swipe handler for all directions
    swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
      //$(this).text("You swiped " + direction );
      if (direction == "left"){
          //action

          //end action              
      };
      if (direction == "right"){
          //swipe action

          //end action             
      };
    },
     threshold:200
  });
});

如何在滑动创建时运行hamburger_cross()(在滑动操作和//结束操作之间)?

1 个答案:

答案 0 :(得分:0)

让汉堡包交叉功能全球化:

$(document).ready(function () {
var trigger = $('.hamburger'),
  overlay = $('.overlay'),
  isClosed = false;

$(".hamb-button").click(function () {
  hamburger_cross();
  $('#wrapper').toggleClass('toggled');      
 });

 function hamburger_cross() {

  if (isClosed == true) {          
    overlay.hide();
    trigger.removeClass('is-open');
    trigger.addClass('is-closed');
    isClosed = false;
  } else {   
    overlay.show();
    trigger.removeClass('is-closed');
    trigger.addClass('is-open');
    isClosed = true;
   }
  }

 //make it global:
 window.hamburger_cross=hamburger_cross;

  $('[data-toggle="offcanvas"]').click(function () {
    $('#wrapper').toggleClass('toggled');
  });  
});

现在你可以做到

hamburger_cross();

...到处