简体   繁体   中英

Window height jquery function returns undefined value

$(window).height(); returns no values says its undefined.

                         var modalHeight = $(window).height();

                        $('.inside-body-wrapper').css("max-height",modalHeight);
                        $('.overlay').css("height",modalHeight);
                        $('.modal').css({
                            display: "block",
                            height: modalHeight
                        });

下面是控制台的屏幕截图。

You can use..

$(document).ready(function() {     

  var wt = $(window).width();
  var ht = $(window).height();
  ....
  ....    
});

The reason is clear if you think about what jquery actually does, it's returning the height style property for whatever you give the selector. As window doesn't have that it will be undefined.

You could instead try using window.outerHeight or window.innerHeight to get those properties instead which could be useful.

您可以使主体标记为100%高度,然后获得主体的高度而不是窗口的高度。

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