Skip to content

Instantly share code, notes, and snippets.

@haroldiedema
Created August 3, 2014 10:10
Show Gist options
  • Save haroldiedema/9b41233289c159df3017 to your computer and use it in GitHub Desktop.
Save haroldiedema/9b41233289c159df3017 to your computer and use it in GitHub Desktop.
Slider snippet -> Function
// Orgineel:
$(window).resize(function() {
// Iterate over slides to find the one with the maximum height.
// Once found, store it in the max_height variable.
max_height = 0;
$(".swiper-container .slide").each(function() {
// First, we get rid of our previously set height, in case
// the content container is getting smaller instead of larger.
$(this).css('height', 'auto');
// If the current value of max_height is less than the height
// of the current iteration, apply the height of this element
// to the max_height varible.
if (max_height < $(this).height()) {
max_height = $(this).height();
}
});
// Iterate over the slides again to apply the max height to all.
$(".swiper-container .slide").each(function() {
$(this).css('height', (max_height)+ 'px');
});
}).resize();
// Functie:
/**
* Automatically adjusts the height of all slides based on the one slide
* which has the largest height value.
*
* @param string container_class
* @param string slide_class
*/
var autoHeightFillSwiper = function(container_class, slide_class)
{
$(window).resize(function() {
// Iterate over slides to find the one with the maximum height.
// Once found, store it in the max_height variable.
max_height = 0;
$(container_class + " " + slide_class).each(function() {
// First, we get rid of our previously set height, in case
// the content container is getting smaller instead of larger.
$(this).css('height', 'auto');
// If the current value of max_height is less than the height
// of the current iteration, apply the height of this element
// to the max_height varible.
if (max_height < $(this).height()) {
max_height = $(this).height();
}
});
// Iterate over the slides again to apply the max height to all.
$(container_class + " " + slide_class).each(function() {
$(this).css('height', (max_height)+ 'px');
});
}).resize();
}
// Usage:
autoHeightFillSwiper('.swiper-container', '.slide');
autoHeightFillSwiper('.swiper-container2', '.slide');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment