【问题标题】:How to update wrap content div when resizing?调整大小时如何更新包装内容div?
【发布时间】:2017-09-01 14:49:39
【问题描述】:

我正在使用 jQuery Ui 创建一个带有拖动和调整大小的网格,元素具有不同类型的内容、文本和图像。当我调整元素的高度时,它不会随内容高度更新,例如。例如,不重新计算新的图像高度。

HTML

<div class="column">
    <div class="portlet">
        <div class="portlet-header">Feeds</div>
        <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
    <div class="portlet">
        <div class="portlet-header">News</div>
        <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
</div>
<div class="column">
    <div class="portlet">
        <div class="portlet-header">Shopping</div>
        <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
    </div>
</div>
<div class="column">
    <div class="portlet">
        <div class="portlet-header">Links</div>
        <div class="portlet-content"><img src="https://s-media-cache-ak0.pinimg.com/736x/12/64/da/1264da4a3f18207dc22592102abae40d--frangipani-tattoo-plumeria-flowers.jpg"></div>
    </div>
</div>

JS

$(function () {
    $(".column").sortable({
        connectWith: ".column",
        placeholder: 'ui-state-highlight',
        forcePlaceholderSize: true
    });

    $(".portlet").resize(function() {
        var myHeight = $(".portlet-content").scrollHeight;
        $(".portlet").outerHeight(myHeight);    
    });

    $(".portlet").resizable().addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
        .find(".portlet-header")
        .addClass("ui-widget-header ui-corner-all")
        .prepend("<span class='ui-icon ui-icon-minusthick'></span>")
        .end()
        .find(".portlet-content");
    $(".portlet-header .ui-icon").click(function () {
        $(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
        $(this).parents(".portlet:first").find(".portlet-content").toggle();
    });
    $(".column").disableSelection();
});

JsFiddle here尝试用图片调整盒子的大小,你会看到它没有更新它的包装高度

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-ui-sortable jquery-ui-resizable


    【解决方案1】:

    好吧,看来我已经解决了:

    $(".portlet").resize(function() {
        $(".portlet").css("height", "auto");
    });
    

    并在 css 中提供:

    .portlet-content {
        padding: 5px;
        height: 100%;
        float: left;
    }
    

    工作jsFiddle

    不确定这是否是最好的方法,但有效

    【讨论】:

    • 似乎运作良好。您可能还想将 overflow: hidden; 添加到类 .portlet 以修复不换行的行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    相关资源
    最近更新 更多