简体   繁体   English

在Ajax加载div后将高度应用于div

[英]Apply height to div after it's loaded by Ajax

I got a shopping cart layer that loads by ajax and shows up in the middle of the screen when clicking a button. 我得到了一个购物车图层,该图层由ajax加载,并在单击按钮时显示在屏幕中间。 I am trying to apply height to it. 我正在尝试对其施加高度。 Successfully managed to do that when I resize the window, but need to apply the same code instantly when that layer loads. 当我调整窗口大小时成功地做到了这一点,但是在加载该层时需要立即应用相同的代码。 The function calculates the content area size, so I can't use it on page load or at any other time, except for the same time it is loaded. 该函数计算内容区域的大小,因此,除了页面加载时,我无法在页面加载时或在任何其他时间使用它。

This is my function that works fine for the window resize event: 这是我的功能,适用于窗口调整大小事件:

$(document).ready(function() {
       $(window).resize(function() {
          var bodyheight = $(window).height();
          var cartheight = $('.shopping-cart-main-content').prop('scrollHeight');
          var cartpercent = ((cartheight + 100) / bodyheight) * 100;

          if (cartpercent > 90) {
            $(".main-shopping-cart").css({'height': '90%'});
          }else{
            $(".main-shopping-cart").css({'height': cartpercent + '%'});
          }
       }); 
    });

Any suggestions how to apply it when the ajax layer appears? 有什么建议如何在ajax层出现时应用它?

将更改高度的相同代码放入AJAX调用的成功函数中

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

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