我使用过$(window).width()和$(window).outerWidth(),但两者都将忽略滚动条。因此,如果滚动条宽度为15 be,那么当媒体查询为770 be时,$(window).width()和$(window).outerWidth()将为755 be。
发布于 2015-01-20 03:14:39
这是因为CSS使用的是设备宽度,JS使用的是文档宽度。
这里有一个js函数来获得viewport的宽度:
function viewport() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
}https://stackoverflow.com/questions/28037092
复制相似问题