2017-05-15 12 views
0

要素にjQueryプラグインが添付されているため、そのプラグインがMobile上でのみ動作するのを止めたいと考えています。別のプラグインが接続されている、ライトボックスですが、私は誰かがモバイルかデスクトップかどうかに関係なく滞在したいと思います。ここでhttps://github.com/mattbryson/TouchSwipe-Jquery-PluginjQueryプラグインをモバイルでのみ無効にしますか?

コードされています:

これは私がモバイル上で停止したいプラグインがある

// Adding in the plugin 
$(function() { 
    $(playlist).swipe({ 
     swipeStatus:function(event, phase, direction, distance, duration) { 
      // code for swipy stuff here .... 
      // ... 
      // ... 
     } 
}); 

// Trying to remove the plugin 
window.onresize = function(event) { 
     var deviceWidth = $(window).width(); 

     if(deviceWidth <= 768) { 
      $(playlist).swipe({ 
       swipeStatus:function(event, phase, direction, distance, duration) { 
        event.preventDefault(); 
        event.stopPropagation(); 
       }, 
       threshold: 0, 
       fingers:'all' 
      }); 
     } 
    }; 

は、あなたが任意のアイデアを得た場合、私に教えてください。また、プレイリストを切り離してDOMに再接続しようとしましたが、それも動作しませんでした。

ありがとうございます!

答えて

0

test,useragentを使用してモバイルデバイスのブラウザであることを確認してから、jqueryを停止することができます。

var isMobileBrowser = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false; 


if(!isMobileBrowser) { 
    $(playlist).swipe({ 
      swipeStatus:function(event, phase, direction, distance, duration) { 
       event.preventDefault(); 
       event.stopPropagation(); 
      }, 
      threshold: 0, 
      fingers:'all' 
     }); 
} 

の詳細を知るためには、user agentは、モバイルデバイスではありませんし、あなたのプラグインを初期化場合は、確認することができ、リンク know useragent

0

を検討してください。

デモ:

function isMobile() { 
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) 
return true; 
} 

if(!isMobile()) { 
    $(playlist).swipe({ 
     swipeStatus:function(event, phase, direction, distance, duration) { 
      event.preventDefault(); 
      event.stopPropagation(); 
     }, 
     threshold: 0, 
     fingers:'all' 
    }); 
} 
関連する問題