Created
August 3, 2014 10:10
-
-
Save haroldiedema/9b41233289c159df3017 to your computer and use it in GitHub Desktop.
Slider snippet -> Function
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
// 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