简体   繁体   中英

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. 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调用的成功函数中

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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