$(window).width() not working in IE9

放肆的年华 提交于 2019-12-01 07:14:17

问题


I am doing something like follow:

// get the screen height and width 
var maskHeight = $(document).height(); 
var maskWidth = $(window).width();

// calculate the values for center alignment
var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2);

But looks like it's not working in IE9.


回答1:


Try this:

var maskWidth = window.innerWidth;
var maskHeight = window.innerHeight;

Or in IE 6+ in standards compliant mode:

var maskWidth = document.documentElement.clientWidth;
var maskHeight = document.documentElement.clientHeight;



回答2:


Use:

$(window).innerHeight();
$(window).innerWidth();


来源:https://stackoverflow.com/questions/7016268/window-width-not-working-in-ie9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!