JQ:dotdot::用浮动子对象展开父对象(高度)

JQ:dotdotdot :: Expand parent (height) with floating child

本文关键字:对象 高度 dotdot JQ      更新时间:2023-09-26

场景:我一直在使用一个jquery脚本,该脚本允许我使用jquery显示/隐藏内容:对于多个嵌套的浮动列,使用dotdot。

问题:现在,当展开时,浮动内容与div.featurediv.featureWrap容器的底部边界重叠。我已经尝试过强制div元素包含溢出的float:hidden,但是。。。没有运气。

期望结果:我希望所选的div.featurediv.featureWrap容器分别展开/折叠。

我相信这很简单,但是。。。我是JS的新手。销毁需要发生什么吗?我看到div.css('max-height','')…

任何帮助都将不胜感激!

请参阅jsfiddle:http://jsfiddle.net/cpardon/tt5htr3s/11/

Jquery:

$(function () {
    $(".desc").dotdotdot({
        ellipsis: '...',
        after: 'a.more',
        wrap: 'word',
        fallbackToLetter: true,
        callback: dotdotdotCallback,
        watch: 'window',
        height: null
    });
    $(".desc").on('click', 'a', function () {
        if ($(this).text() == "More") {
            var div = $(this).closest('.desc');
            div.trigger('destroy').find('a.more').hide();
            div.css('max-height', '');
            $("a.less", div).show();
        } else {
            $(this).hide();
            $(this).closest('.desc').css("max-height", "60px").dotdotdot({
                after: "a.more",
                callback: dotdotdotCallback
            });
        }
    });
    function dotdotdotCallback(isTruncated, originalContent) {
        if (!isTruncated) {
            $("a", this).remove();
        }
    }
});

CSS:

.left {float:left;}
.clearboth {clear:both;}
#featureWrap {width:100%;}
#featureWrap .feature {width:100px;margin:0 5px;border:1px solid #CCC;padding:7px;}
#featureWrap .feature .title {color:#777;padding:12px 0;font-size:20px;}
#featureWrap .feature .desc {font-size:12px;line-height:19px;color:#555;max-height:60px;}
#featureWrap .feature .desc a {color: rgb(224, 86, 40);text-decoration: none;}
#featureWrap .feature .desc a:hover {color: #666;text-decoration: none;}
#featureWrap .feature .desc a.less {display: none;}

更改第15行:

div.css('max-height', '');

div.css('max-height', 'none');

Fiddle

您的原始代码将尝试将样式设置为与''内联,这反过来又试图清除最大高度,但您的样式max-height: 60px;是在CSS中设置的。通过放置max-height: none;,它具有更高的优先级