简体   繁体   English

使用Gridstack容器调整高度

[英]Div resizing height with Gridstack container

I'm using the Gridstack.js framework in an app and have some div columns: 我在应用程序中使用Gridstack.js框架,并且有一些div列:

<div class="col-lg-6 s_panel">
<div class="cont">
<!-- 1st div content -->
</div>
</div>  

<div class="col-lg-6 s_panel">
<div class="grid-stack">
<!-- Gridstack content -->
</div>
</div>

And I'm setting the height of the 1st Div to be the same as whatever the Gridstack container is like this: 我将第一个Div的高度设置为与Gridstack容器一样:

$(document).ready(function () {          
     var divHeight = $('.grid-stack').css("height");
     $('.cont').css('height', divHeight);
});

So on load the divs are both the same height, but if the Gridstack div has more items added to it and grows in height I wanted the 1st div to also be the same height. 因此,在加载时,div的高度都相同,但是如果Gridstack div中添加了更多项并增加了高度,我希望第一个div的高度也相同。

Is there a way to dynamically make the 1st div change height to be the same as the Gridstack div as its adjusted? 有没有一种方法可以动态地使第一个div的更改高度与调整后的Gridstack div相同?

In case you're using ajax call, I would suggest you should create a function of height change instead of $(document).ready like so: 如果您使用的是ajax调用,我建议您创建一个高度变化函数,而不是$(document).ready像这样:

var helpers = {
    heightChange() {
        var divHeight = $('.grid-stack').css("height");
        $('.cont').css('height', divHeight);
    }
};

And then in your ajax call to makes change/put data in .grid-stack you only need to call your function, full code for example: 然后,在您的ajax调用中,在.grid-stack进行更改/放置数据时,您只需要调用函数,例如完整代码:

 <script type="text/javascript">
    var helpers = {
        heightChange() {
            var divHeight = $('.grid-stack').css("height");
            $('.cont').css('height', divHeight);
        }
    };

    $.ajax({
        url: "test.php",
        type: "post",
        data: values ,
        success: function (response) {
            $('.grid-stack').append(response);
            //call height change here
            helpers.heightChange();
        },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log(textStatus, errorThrown);
        }
    });
</script>

Hope this help, feel free to tell me your other problem. 希望有帮助,请随时告诉我您的其他问题。

This might help you https://jsfiddle.net/4uqd3jqL/ 这可能对您有帮助https://jsfiddle.net/4uqd3jqL/

 $(document).ready(function () { $('.cont').css('height', $('.grid-stack').css("height")); setTimeout(function(){ $('.grid-stack').css("height", $(this).height() + 100); $('.cont').css('height', $('.grid-stack').css("height")); }, 1000); }); 
 .grid-stack{ height:300px; background: red; } .cont{ height:200px; background: blue; } .col-lg-6{ width:50%; display: inline-block; float:left; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="col-lg-6 s_panel"> <div class="cont"> <!-- 1st div content --> </div> </div> <div class="col-lg-6 s_panel"> <div class="grid-stack"> <!-- Gridstack content --> </div> </div> 

Since I don't have any Ajax call, I have used setTimeout . 由于我没有任何Ajax调用,因此我使用了setTimeout

In setTimeout I'm increasing the height of grid-stack container by 100px & then setting the height of cont by height of grid-stack 在setTimeout的我100像素 提高 电网堆容器的高度和再由电网栈的高度设定高度

You can achieve this simply using css without nay jquery or javascript . 您可以简单地使用css来实现此目的,而无需使用jqueryjavascript

Use css flex properties. 使用css flex属性。

 .s_panel_container { display: flex; } .s_panel { flex: 1; } .cont { background-color: pink; } .grid-stack { background-color: #ccfff5; } 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="s_panel_container"> <div class="col-lg-6 s_panel cont"> 1st div content </div> <div class="col-lg-6 s_panel grid-stack"> It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM