这让我发疯。我有很多次旋转木马,我需要用JavaScript来重置屏幕高度。问题是,对于移动设备,屏幕高度包括顶部的小URL窗口,因此页面的高度由“window.innerHeight”或$(window).height()计算;已关闭。这有解决方法吗?一直发生。
答案 0 :(得分:0)
使用' clientWidth'和' clientHeight'代替
答案 1 :(得分:0)
这取决于缩放是否受视口影响。只需使用普通的js来获取值。控制起来会容易得多:
//Screen
var w = screen.width;
var h = screen.height;
console.log('screen = ',w,' & ',h);
//Screen with ratio
var ratio = window.devicePixelRatio || 1;
var w = screen.width * ratio;
var h = screen.height * ratio;
console.log('screen = ',w,' & ',h);
//Document
//PS document.width & document.height is no longer supported
var w = window.innerWidth
|| document.documentElement.clientWidth //for IE 8 or lower
|| document.body.clientWidth; //for IE 8 or lower
var h = window.innerHeight
|| document.documentElement.clientHeight //for IE 8 or lower
|| document.body.clientHeight; //for IE 8 or lower
console.log('client = ',w,' & ',h);
//Document offset
var w = document.body.offsetWidth
var h = document.body.offsetHeight
console.log('offset = ',w,' & ',h);
//Document fractional offset
var c = document.body.getBoundingClientRect()
console.log(c);
//Scroll
var x = window.scrollX || window.pageXOffset;
var y = window.scrollY || window.pageYOffset;
console.log('scroll = ',x,' & ',y);
享受;)