编程语言
首页 > 编程语言> > javascript – $(window).width()在IE9中不起作用

javascript – $(window).width()在IE9中不起作用

作者:互联网

我正在做类似的事情:

// 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);

但看起来它在IE9中不起作用.

解决方法:

试试这个:

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

或者在标准兼容模式的IE 6中:

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

标签:javascript,jquery,cross-browser,internet-explorer-9
来源: https://codeday.me/bug/20190723/1515392.html