简体   繁体   English

在 ajax 调用之后保持之前的 div 高度

[英]maintain previous div height after ajax call

I am dealing with the following issue.我正在处理以下问题。 I have a script that is calling ajax in which the response contains cart string (html code) with items of my cart.我有一个调用 ajax 的脚本,其中响应包含购物车字符串(html 代码)和我的购物车物品。 Withtin the responsehandler I have another script that is setting each of the divs of the ajax response cart string to a certain height.在响应处理程序中,我有另一个脚本,它将 ajax 响应购物车字符串的每个 div 设置为一定的高度。

Now I am willing to maintain the div height that was set to the previous cart string, but the problem is the entire cart string is received over again after every ajax call.现在我愿意保持设置为前一个购物车字符串的 div 高度,但问题是每次 ajax 调用后都会重新接收整个购物车字符串。

In addition I have another cart (mobile only) which shows up in a bootstrap modal.此外,我还有另一个显示在引导模式中的购物车(仅限移动设备)。 Somehow this function for setting the height is not working on unless you open it and run the function again.不知何故,这个用于设置高度的 function 不起作用,除非你打开它并再次运行 function。 Does this have something to do with the modal display:none?这是否与模态显示有关:无? The function is looping through all div with same class name and sets the height according to its child data. function 循环遍历具有相同 class 名称的所有 div,并根据其子数据设置高度。

You can fix the div's height by using css.您可以使用 css 来修复 div 的高度。

div.cart-height{
  height: 400px !important;
}

or after ajax call, resize the div's height.或在 ajax 调用之后,调整 div 的高度。

$('.cart-height').css('height','400px');

In mobile you can adjust content:在移动设备中,您可以调整内容:

@media only screen and (max-width: 600px) {
  .cart-height {
    height: 200px;
  }
}

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

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