如何避免在小视口上打开litebox?

时间:2015-10-13 22:20:16

标签: javascript jquery mobile jquery-plugins

我想避免在Android或Apple设备上的小视口中打开litebox

这是我尝试过的,没有成功:



$( document ).ajaxComplete( function() {	

    $('.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();
            }
        } 
    });	
		
});
&#13;
<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>
&#13;
&#13;
&#13;

我收到了错误......

  

TypeError:$(...)。closeLitebox不是函数

     

$(本).closeLitebox();

1 个答案:

答案 0 :(得分:1)

也许不是在Litebox函数中关闭它,试着阻止它甚至进入它?

您可以尝试:

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

if (!isMobile.matches) {
    $('.litebox').liteBox...
}