Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This should fix your problem:</p> <p><a href="http://jsfiddle.net/sSqAx/88/" rel="nofollow">JSfiddle</a></p> <p>And one with different heights: <a href="http://jsfiddle.net/sSqAx/91/" rel="nofollow">JSfiddle</a></p> <p><strong>HTML</strong></p> <pre><code>&lt;div class="bxslider"&gt; &lt;div class="bxslider-inner"&gt;&lt;div style="width:80px; height:80px; background:#CCC; padding:5px;"&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="bxslider-inner"&gt;&lt;div style="width:80px; height:80px; background:#F5F5F5; padding:5px;"&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="bxslider-inner"&gt;&lt;div style="width:80px; height:10px; background:#6699cc; padding:5px;"&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="bxslider-inner"&gt;&lt;div style="width:80px; height:80px; background:#F5F5F5; padding:5px;"&gt;&lt;/div&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code>body { background: orange; margin-top: 50px; } .bxslider-inner { vertical-align: middle; display: inline-block; height: 80px; } </code></pre> <p><strong>JavaScript</strong></p> <pre><code>'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('&lt;div style="height: ' + top_margin + 'px; width: 100%;"&gt;&lt;/div&gt;' + $(this).html()); }); }); </code></pre> <p>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 <code>box-sizing: border-box;</code>, so all of that collapses to the inside of the div.</p> <p><code>bxslider-inner</code> 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.</p> <p>Good luck!</p> <p><strong>UPDATE</strong></p> <ul> <li>JSfiddle updated, should not stuck in a loop now.</li> <li>Tested with a too high height, code doesn't seem to break, but might overflow to hidden</li> <li>Look at <a href="http://bxslider.com/options" rel="nofollow">http://bxslider.com/options</a> (> Callbacks > onSlideAfter). You can do modifications after each cycle if needed too. Here you can modify your code again if needed for complexion</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload