$(window).width()在IE9中不工作 [英] $(window).width() not working in IE9

查看:218
本文介绍了$(window).width()在IE9中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做类似如下的操作:

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

但看起来它不能在IE9中工作。

But looks like it's not working in IE9.

推荐答案

尝试这样:

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

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

Or in IE 6+ in standards compliant mode:

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

这篇关于$(window).width()在IE9中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆