Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS matchMedia if语句_Javascript_Jquery_Fancybox 2_Matchmedia - Fatal编程技术网

Javascript JS matchMedia if语句

Javascript JS matchMedia if语句,javascript,jquery,fancybox-2,matchmedia,Javascript,Jquery,Fancybox 2,Matchmedia,我正在尝试触发我的fancybox for viewports>=768px,并触发我的swipebox for viewports试试这个。我也会更新小提琴 “我很确定这是语法错误”-你为什么这么说?如果您知道错误,请将其添加到问题中。你在跑步的时候看过控制台了吗?我在JS方面有点新手。。。我这样说是因为swipebox和fancybox位单独工作,但再加上if语句,什么都不会发生(没有打开的灯箱)。。。因此,我认为这一定是语法错误。我试图在控制台中理解它,但它太高级了,我无法理解..打开C

我正在尝试触发我的fancybox for viewports>=768px,并触发我的swipebox for viewports试试这个。我也会更新小提琴


“我很确定这是语法错误”-你为什么这么说?如果您知道错误,请将其添加到问题中。你在跑步的时候看过控制台了吗?我在JS方面有点新手。。。我这样说是因为swipebox和fancybox位单独工作,但再加上if语句,什么都不会发生(没有打开的灯箱)。。。因此,我认为这一定是语法错误。我试图在控制台中理解它,但它太高级了,我无法理解..打开Chrome,打开开发工具(菜单>更多工具>开发人员工具),然后打开控制台(或者,如果你在mac上,则打开option+command+J)。然后刷新页面。严重的是,除非你能用控制台做基本的故障排除,否则我们不会走得很远。你也可以考虑把你的代码放到JSFiddle,这样我们就可以合作地进行故障排除。谢谢,是的,你是对的,我需要开始更多地研究调试工具!我在这里做了一个简化版本:
$(document).ready(function() {
if (window.matchMedia("(min-width: 768px)").matches) {

  $(".fancybox").fancybox({
    //width: '70%',
    //height: '70%',
      helpers: {
        overlay: {
          locked: false
        }
      },
    'beforeLoad': function(){
      disable_scroll();
        },
     'afterClose': function(){
       enable_scroll();
      }

  });


var keys = [37, 38, 39, 40];

    function preventDefault(e) {
      e = e || window.event;
      if (e.preventDefault) e.preventDefault();
      e.returnValue = false;  
    }

    function keydown(e) {
        for (var i = keys.length; i--;) {
            if (e.keyCode === keys[i]) {
                preventDefault(e);
                return;
            }
        }
    }

    function wheel(e) {
      preventDefault(e);
    }

    function disable_scroll() {
      if (window.addEventListener) {
          window.addEventListener('DOMMouseScroll', wheel, false);
      }
      window.onmousewheel = document.onmousewheel = wheel;
      document.onkeydown = keydown;
    }

    function enable_scroll() {
        if (window.removeEventListener) {
            window.removeEventListener('DOMMouseScroll', wheel, false);
        }
        window.onmousewheel = document.onmousewheel = document.onkeydown = null;  
    }
} else {
  ( function( $ ) {

    $( '.swipebox' ).swipebox();

  } )( jQuery );
}
});