This should fix your problem:
JSfiddle
And one with different heights: JSfiddle
HTML
<div class="bxslider">
<div class="bxslider-inner"><div style="width:80px; height:80px; background:#CCC; padding:5px;"></div></div>
<div class="bxslider-inner"><div style="width:80px; height:80px; background:#F5F5F5; padding:5px;"></div></div>
<div class="bxslider-inner"><div style="width:80px; height:10px; background:#6699cc; padding:5px;"></div></div>
<div class="bxslider-inner"><div style="width:80px; height:80px; background:#F5F5F5; padding:5px;"></div></div>
</div>
CSS
body {
background: orange;
margin-top: 50px;
}
.bxslider-inner {
vertical-align: middle;
display: inline-block;
height: 80px;
}
JavaScript
'use strict';
jQuery(document).ready(function(){
jQuery('.bxslider').bxSlider({
mode: 'horizontal',
speed: 500,
slideMargin:20,
infiniteLoop: true,
pager: false,
controls: true,
slideWidth: 80,
minSlides: 1,
maxSlides: 5,
moveSlides: 1
}
});
// Initial
$('.bxslider-inner').each(function(){
var height_parent = $(this).css('height').replace('px', '') * 1;
var height_child = $('div', $(this)).css('height').replace('px', '') * 1;
var padding_top_child = $('div', $(this)).css('padding-top').replace('px', '') * 1;
var padding_bottom_child = $('div', $(this)).css('padding-bottom').replace('px', '') * 1;
var top_margin = (height_parent - (height_child + padding_top_child + padding_bottom_child)) / 2;
$(this).html('<div style="height: ' + top_margin + 'px; width: 100%;"></div>' + $(this).html());
});
});
Keep in mind that the calculated middle is very dependent on other height variables like padding, margin and borders. If you add styles like that, keep in mind that you need to add those to the calculation. Another option is to use box-sizing: border-box;
, so all of that collapses to the inside of the div.
bxslider-inner
MUST have a height, or you need to somehow fetch the calculated DOM height to avoid it. If you really want that, please leave a note and I'll look into it.
Good luck!
UPDATE
- JSfiddle updated, should not stuck in a loop now.
- Tested with a too high height, code doesn't seem to break, but might overflow to hidden
- Look at http://bxslider.com/options (> Callbacks > onSlideAfter). You can do modifications after each cycle if needed too. Here you can modify your code again if needed for complexion