在jQuery旋转内容div中,如何使div始终与最高内容一样高?

时间:2014-01-04 21:09:26

标签: jquery

我有点像jQuery noob。我知道在我喜欢的jQuery插件上找到并实现并做一些自定义,但还不足以编写我自己的插件。我最近发现了这个:http://sandbox.sebnitu.com/jquery/quovolver/我非常喜欢它,我现在正在网站上使用它。

我遇到的问题是,正如您在上面的示例页面上看到的那样,包含引号的div会根据当前显示的内容的高度更改高度。当出现新报价时,div的高度随之变化。如何确定div的最大高度并使其始终为高度,以便旋转报价div下方的内容不会上下移动?

1 个答案:

答案 0 :(得分:1)

你可以抓住最高元素,并将所有其他元素的高度设置为该高度。

在您的示例中,元素没有class属性,您当然应该将它们添加到它们中,所以它们都是这样的<blockquote class="quote">Quote</blockquote>

/*Run when the DOM is ready.*/
$(function() {

    //We will populate this variable with the height of the highest quote element
    var heightOfHighest=0;

    //Lets iterate all quote elements, to figure the highest.
    $(".quote").each(function () {

            //If this elements hight is larger than the one already set, we set the variable with the new height
            if ( $(this).height() > heightOfHighest ) {
                heightOfHighest = $(this).height();
            }
    });

    //Now, once again. iterate all quote elements
    $(".quote").each(function () {
        //Set the height of each and every quote object to the same as the highest of them.
        $(this).height( heightOfHighest );
    });
}