我正在使用
jquery mobile,我需要防止特定元素上的滑动事件.需要这样做是因为我使用滑块,我不希望调用滑动事件.当用户使用滑块操作时,我希望它被阻止.我无法找到任何解决方案,所以我在这里寻求帮助.
这是我的javascript代码:
$( document ).on( "pageinit","#demo-page",function() { $( document ).on( "swipeleft swiperight",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" ); } } }); });
谢谢.
解决方法
你需要同时使用stopPropagation();和preventDefault();.
对于.selector,它可以是标签和#ID或.class,例如[data-role = page]#PageID,div.ui-content …等
$(document).on('swipeleft swiperight','.selector',function(event) { event.stopPropagation(); event.preventDefault(); });
>参考:stopPropagation();
>参考:preventDefault();
> Working example
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。