Reputation: 6374
I'm using FlexSlider 2.2.2 and he following snippet is generating two jQuery errors
Uncaught TypeError: Cannot read property 'vars' of undefined Uncaught ReferenceError: SyntaxHighlighter is not defined
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.
Upvotes: 0
Views: 7955
Reputation: 193
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;
});
}());
});
Upvotes: 0
Reputation: 18109
I couldn't reproduce the syntaxhighlighter error. but flexslider error was because you were not initializing the flexslider variable.
Working Demo: 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.
Upvotes: 3