2010-07-08 67 views
9

我使用一些div的cycle plugin,這樣的自動高度:的jQuery Cycle插件 - 集裝箱

<div class="sections"> 
    <div class="Section"> <img /> text </div> 
    <div class="Section"> <img /> text </div> 
    <div class="Section"> <img /> text </div> 
</div> 

所有.section僞的div有不同的高度,基於它們的內容。 如何讓循環不要調整容器格(部分)到最大的兒童身高?相反,我希望容器將每個動畫的大小調整爲當前的子高度。

+0

什麼是您當前的CSS代碼? – Marko 2010-07-08 12:30:52

+0

對於.sections/.section,根本沒有css。我應該添加任何CSS? 上面的html位於頁面側邊欄。在它下面可以添加其他內容,這就是爲什麼我需要自動高度容器 – Alex 2010-07-08 12:32:36

回答

12

設置containerResize選項爲0並嘗試。更多選項詳情here

+2

您必須使用完整版本,而不是精簡版。 – eveevans 2011-09-17 17:19:59

21

好吧,我設法事件「後」鉤在一個函數來做到這一點:

function onAfter(curr, next, opts, fwd) { 
    var $ht = $(this).height(); 

    //set the container's height to that of the current slide 
    $(this).parent().animate({height: $ht}); 
} 

發現這裏的信息: http://forum.jquery.com/topic/jquery-cycle-auto-height

+1

這很好,但是我怎樣才能得到循環以在動態添加內聯內容後重新計算高度? – Florian 2011-12-14 20:36:16

1

我已經做了不同的一點:

$('.cycle-list').cycle({ 
    containerResize: 0, 
    before: function(currSlideElement, nextSlideElement, options, forwardFlag) { 
     var container = $(this).parent(); 
     container.css('height', Math.max(container.height(), $(nextSlideElement).height())); 
    }, 
    after: function(currSlideElement, nextSlideElement, options, forwardFlag) { 
     $(this).parent().css('height', $(this).height()); 
    } 
    }); 

我的物品也有不同的高度。在之前的版本中,它確保容器足夠大,可容納2張幻燈片中較大的一張。在後,它只是調整到下一張幻燈片。 這種方式不會因爲您的容器太小而過度流動。

注意:這是用於循環1