2013-03-30 9 views
6

पर JQuery मोबाइल स्वाइप ईवेंट को रोकें मैं jquery मोबाइल का उपयोग कर रहा हूं और मुझे विशिष्ट तत्व पर स्वाइप ईवेंट को रोकने की आवश्यकता है। ऐसा करने की आवश्यकता इसलिए है क्योंकि मैं स्लाइडर का उपयोग कर रहा हूं और मैं नहीं चाहता कि स्वाइप ईवेंट को सांस लगाया जाए। जब मैं स्लाइडर के साथ छेड़छाड़ कर रहा हूं तो मैं इसे रोकना चाहता हूं। मुझे कोई समाधान भी नहीं मिला, इसलिए मैं यहां मदद मांग रहा हूं।विशिष्ट तत्व

यह मेरा जावास्क्रिप्ट कोड है:

$(document).on("pageinit", "#demo-page", function() { 
    $(document).on("swipeleft swiperight", "#demo-page", function(e) { 

    // We check if there is no open panel on the page because otherwise 
    // a swipe to close the left panel would also open the right panel (and v.v.). 
    // We do this by checking the data that the framework stores on the page element (panel: open). 

    if ($.mobile.activePage.jqmData("panel") !== "open") { 
    if (e.type === "swipeleft" ) { 
     $("#right-panel").panel("open"); 
     } else if (e.type === "swiperight") { 
      $("#left-panel").panel("open"); 
     } 
    } 
    }); 
}); 

धन्यवाद।

उत्तर

11

आपको stopPropagation(); और preventDefault(); दोनों का उपयोग करने की आवश्यकता है।

.selector का सवाल है, यह एक टैग हो सकता है और #ID या .class, उदा [data-role=page]#PageID, div.ui-content ... आदि

$(document).on('swipeleft swiperight', '.selector', function(event) { 
event.stopPropagation(); 
event.preventDefault(); 
}); 
खैर मेरे मामले में
+0

, इस के लिए स्लाइडर को रोकता है चले जाओ लेकिन पी नहीं आयु संक्रमण ... क्या इसे प्राप्त करना संभव है .on ('स्वाइप', ': नहीं (.ui-slider)', संक्रमण)? – IazertyuiopI

+0

@IazertyuiopI आप निश्चित रूप से ': not()' चयनकर्ता का उपयोग कर सकते हैं। उदाहरण के लिए – Omar

+0

, चयनकर्ता = '" स्वाइप बाएं "," .foo: नहीं (.ui-slider) ", function'। @IazertyuiopI – Omar

संबंधित मुद्दे