简体   繁体   English

FlexSlider未捕获的TypeError和ReferenceError

[英]FlexSlider Uncaught TypeError and ReferenceError

I'm using FlexSlider 2.2.2 and he following snippet is generating two jQuery errors 我正在使用FlexSlider 2.2.2,他下面的代码段生成了两个jQuery错误

Uncaught TypeError: Cannot read property 'vars' of undefined Uncaught ReferenceError: SyntaxHighlighter is not defined 未捕获的TypeError:无法读取未定义的属性'vars'未捕获的ReferenceError:未定义SyntaxHighlighter

        jQuery(document).ready(function(){

  // store the slider in a local variable
  var jQuerywindow = jQuery(window),
      flexslider;

  // tiny helper function to add breakpoints
  function getGridSize() {
    return (window.innerWidth < 600) ? 1 :
           (window.innerWidth < 900) ? 3 : 3;
  }

  jQuery(function() {
    SyntaxHighlighter.all();
  });

  jQuery('.flexslider').flexslider({
    animation: "slide",
    animationLoop: false,
    itemWidth: 290,
    itemMargin: 0,
    prevText: " ",
    nextText: " ",
 minItems: getGridSize(), // use function to pull in initial value
      maxItems: getGridSize() // use function to pull in initial value
    });
 // check grid size on resize event
  jQuery(window).resize(function() {
    var gridSize = getGridSize();

    flexslider.vars.minItems = gridSize;
    flexslider.vars.maxItems = gridSize;
  });
});

Edit : highight error for better visibility. 编辑:高度错误,以获得更好的可见性。

I couldn't reproduce the syntaxhighlighter error. 我无法重现语法高亮错误。 but flexslider error was because you were not initializing the flexslider variable. 但是flexslider错误是因为您没有初始化flexslider变量。

Working Demo: http://jsfiddle.net/lotusgodkk/nwjra/23/ 工作演示: http : //jsfiddle.net/lotusgodkk/nwjra/23/

    jQuery('.flexslider').flexslider({
    animation: "slide",
    animationLoop: false,
    itemWidth: 290,
    itemMargin: 0,
    prevText: " ",
    nextText: " ",
    minItems: getGridSize(),
    maxItems: getGridSize(),
    start: function (slider) {
        flexslider = slider; //Initializing flexslider here.
    }
});

You can also see that the syntaxhighlight error does not appear here. 您还可以看到语法高亮错误没有出现在这里。

start: function(slider){
        flexslider = slider;
       }

and

var $window = $(window),
    flexslider = { vars:{} };

Does the trick for me. 对我有用吗?

Complete code: 完整的代码:

jQuery(document).ready(function() {
    // Carousel with dynamic min/max ranges
    (function() {

        // store the slider in a local variable
        var $window = $(window),
            flexslider = { vars:{} };

        // tiny helper function to add breakpoints
        function getGridSize() {
            return (window.innerWidth < 480) ? 1 :
                (window.innerWidth < 900) ? 2 : 3;
        }

        $window.load(function() {
            $('.flexslider').flexslider({
                animation: "slide",
                animationLoop: true,
                itemWidth: 210,
                itemMargin: 0,
                controlNav: false,
                minItems: getGridSize(), // use function to pull in initial value
                maxItems: getGridSize(), // use function to pull in initial value
                start: function(slider){
                    flexslider = slider;
                }
            });
        });

        // check grid size on resize event
        $window.resize(function() {
            var gridSize = getGridSize();

            flexslider.vars.minItems = gridSize;
            flexslider.vars.maxItems = gridSize;
        });
    }());
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的 TypeError 和未捕获的 ReferenceError - Uncaught TypeError and Uncaught ReferenceError Shopify Flexslider问题:未捕获的TypeError:$(…).flexslider不是函数 - Shopify Flexslider Issue: Uncaught TypeError: $(…).flexslider is not a function 未捕获的TypeError:jQuery(...)。flexslider不是函数 - Uncaught TypeError: jQuery(…).flexslider is not a function 未捕获的类型错误:$(...).flexslider 不是使用 gulp 和 bower 的函数 - Uncaught TypeError: $(…).flexslider is not a function using gulp and bower 为什么在使用Flexslider时会出现“ Uncaught TypeError”? - Why am I getting “Uncaught TypeError” when using Flexslider? FlexSlider不起作用-“未捕获的TypeError:未定义不是函数”(Typo3) - FlexSlider does not work - “Uncaught TypeError: undefined is not a function” (Typo3) 遇到未捕获的ReferenceError:未定义_和未捕获的TypeError:未定义不是函数 - Getting uncaught ReferenceError: _ is not defined and Uncaught TypeError: undefined is not a function 我不断收到Uncaught ReferenceError:未定义dropMenu和Uncaught TypeError:无法读取null的属性&#39;style&#39; - i keep getting Uncaught ReferenceError: dropMenu is not defined and Uncaught TypeError: Cannot read property 'style' of null 未捕获的TypeError:无法调用null的方法“观察” /未捕获的ReferenceError:未定义可拖动 - Uncaught TypeError: Cannot call method 'observe' of null / Uncaught ReferenceError: Draggable is not defined jQuery Flexslider 未捕获的类型错误 - Uncaught type Error by jQuery Flexslider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM