2014-01-28 52 views
0

因此,我實現了一個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 <<<'好點..應該有一個查詢事件。 :)

所以這裏來了我的困難。我發現了一個很棒的關閉畫布菜單插件(如果它至少被稱爲插件..)檢查Github在這裏 - >SidebarTransitions和演示 - >Demo here。但是,這是基於點擊一個按鈕。我想執行單擊按鈕('Reveal',ST-effect-2,準確地說,在演示中看到)作爲可執行的JS事件發生的事件,插入Swipe行代碼中。

因此,在'>>>Jquery event should be placed here <<<'部分應該有一行或幾行代表打開側邊欄的按鈕後面的代碼,所以用戶可以通過輕掃打開邊欄而不是點擊按鈕。所以沒有.click().on()

對於SidebarTransitions的Javascript中的視圖,而不是查看所有腳本,這是完全執行側邊欄打開/關閉所必需的唯一一個。 >here

哦,順便說一句,關閉的線(我可以放在不同方向的刷卡代碼後面)也會很棒!

非常感謝你們。希望你們能弄明白,因爲在過去的幾個小時裏,我沒有辦法。

的jsfiddle - >>here! 注:對於那些具有多點觸摸觸控板或輕掃選項,刷卡用一個或多個手指(我需要三到刷卡)的結果框和你應該得到'yup'的提醒來驗證你能夠刷卡。哦..而忽略CSS

回答

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 */ 
+0

你錯過了一個 「'」 在'$('[數據效果=「ST-效應 - 2「])',我很高興地注意到這一點。這修正了一個小小的錯誤,並形成了一套完整的工作代碼。你我的男人,太棒了!但是,我無法驗證左側的一段代碼是否正在工作,奇怪。 –

+0

我已修復代碼中的錯誤。 – guli

相關問題