[英]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. 对我有用吗?
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.