如何在另一个事件的按钮上模拟点击事件

时间:2014-01-28 21:45:21

标签: jquery event-handling click html5-canvas sidebar

所以我实现了一个jQuery Swipe插件TouchSwipe,让我根据一定的滑动执行jQuery事件。所以我得到了这段代码..

    $(function() {   /* Swipe gestures */    
      //Enable swiping...
      $(document).swipe( {
        //Generic swipe handler for all directions
        swipeRight:function(event, direction, distance, duration, fingerCount) {
              $('.off-canvas-wrap').toggleClass('move-right');
              >>>JQUERY EVENT SHOULD BE PLACED HERE<<< 
        },
        swipeLeft:function(event, direction, distance, duration, fingerCount) {
              $(".off-canvas-wrap").removeClass("move-right"); 
        },

        //Default is 75px, set to 0 for demo so any distance triggers swipe
         threshold:0
      });
    }); /* End of swipe gestures script */

'>>>Jquery event should be placed here <<<'井点......应该有一个查询事件。 :)

所以我遇到了困难。我找到了一个很棒的Off Canvas菜单插件(如果它至少被称为插件.. )在这里检查Github - &gt; SidebarTransitions和演示 - &gt; Demo here。但是,这是基于单击按钮。我想执行当您单击一个按钮(&#39;显示&#39;,ST-effect-2,准确地说,在演示中看到)作为可执行JS事件时插入的事件,插入Swipe行代码。

因此,在'>>>Jquery event should be placed here <<<'的部分应该有一行或几行代表打开侧边栏的按钮背后的代码,因此用户可以打开侧边栏,而不是单击按钮。刷卡。所以没有.click().on()

对于SidebarTransitions的Javascript中的视图,而不是查看所有脚本,这个是唯一一个完美执行侧边栏打开/关闭所必需的脚本。 &GT; here

哦,顺便说一句,关闭的行(我可以放在不同滑动方向的代码后面)也很棒!

非常感谢你们。希望你们能解决这个问题,因为在过去的几个小时里,我没能做到。

JSFiddle - &gt;&gt; here! 注意: 对于那些使用多点触控触控板或任何滑动选项的用户,请在结果框中使用一根或多根手指(我需要三次滑动)进行滑动,您应该会收到警报与&#39;是&#39;验证您是否可以滑动。哦..而忽略了巨大的CSS列表

1 个答案:

答案 0 :(得分:1)

尝试这样做:

$(function() {   /* Swipe gestures */    
  //Enable swiping...
  $(document).swipe( {
    //Generic swipe handler for all directions
    swipeRight:function(event, direction, distance, duration, fingerCount) {
          $('.off-canvas-wrap').toggleClass('move-right');
          $('[data-effect="st-effect-2"]').trigger('click');
    },
    swipeLeft:function(event, direction, distance, duration, fingerCount) {
          $(".off-canvas-wrap").removeClass("move-right"); 
    },

    //Default is 75px, set to 0 for demo so any distance triggers swipe
     threshold:0
  });
}); /* End of swipe gestures script */
相关问题