2015-10-13 21 views
0

我想避免litebox在Android或Apple設備的小視口上打開。如何避免在小視口上打開litebox?

這裏是我試過了,沒有成功:

$(document).ajaxComplete(function() { \t 
 

 
    $('.litebox').liteBox({ 
 
     callbackBeforeOpen: function() { 
 
      console.log('open'); 
 
      var windowsize = $(window).width(); 
 
      // test the viewport size to see if it's smaller than 480px 
 
      if (windowsize < 1000) { 
 
       // cancel the lightbox and load the link url 
 
       console.log('close'); 
 
       $(this).closeLitebox(); 
 
      } 
 
     } 
 
    }); \t 
 
\t \t 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
<script src="https://rawgit.com/joemottershaw/litebox/master/assets/js/litebox.js"></script> 
 

 
<a href="https://www.youtube.com/watch?v=gOLY7bjCTTE" target="_blank" class="litebox">Video</a>

我的錯誤...

TypeError: $(...).closeLitebox is not a function

$(this).closeLitebox();

回答

1

也許不是關閉它litebox函數中,儘量阻止它甚至進入它?

你可以試試:

var isMobile = window.matchMedia("only screen and (max-width: 760px)"); 

if (!isMobile.matches) { 
    $('.litebox').liteBox... 
} 
相關問題