Created
January 18, 2017 18:40
-
-
Save accrane/c612a6e53387a61e51071d3c0d882321 to your computer and use it in GitHub Desktop.
Responsive call to a flexslider carousel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
// store the slider in a local variable | |
var $window = $(window), | |
flexslider = { vars:{} }; | |
// tiny helper function to add breakpoints | |
function getGridSize() { | |
return (window.innerWidth < 600) ? 2 : | |
(window.innerWidth < 900) ? 2 : 3; | |
} | |
$(function() { | |
SyntaxHighlighter.all(); | |
}); | |
$window.load(function() { | |
$('.flexslider').flexslider({ | |
animation: "slide", | |
animationLoop: false, | |
itemWidth: 210, | |
itemMargin: 10, | |
minItems: getGridSize(), // use function to pull in initial value | |
maxItems: getGridSize() // use function to pull in initial value | |
}); | |
}); | |
// check grid size on resize event | |
$window.resize(function() { | |
var gridSize = getGridSize(); | |
flexslider.vars.minItems = gridSize; | |
flexslider.vars.maxItems = gridSize; | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment