Comments (9)
其实这个问题,我在IOS里碰到过好多次,尤其是在用微信打开某个页面时:
该问题为客户端问题,和JavaScript无关,更和各种轮子无关
350*588的手机屏幕,横屏时,获取高度约为300;然后横屏转竖屏的一瞬间,屏幕转换事件触发了(无论是原生orientationchange事件,还是原生resize事件),但那一瞬间获取的高度仍然是300
在适当的延迟几百毫秒之后,才能正确获得旋转之后的高度(大约500)
个人在想,是否可以单独针对这种情况,将旋转事件event,切分为eventStart和eventEnd,eventEnd代表横竖比已经切换完毕
from orientationchange-fix.
@a2631500 不是旋转引起的吧。
我不知道你是否了解:浏览器是如何进行渲染页面的。知道为啥你延迟一下就可以了?(其实这里可以不是300,其他值也行),只要DOM tree准备好了就行。你可以将代码放在body的底部或在$(function(){ //do something.... })也行。看描述我想到就这么多了,也不知道能否解决你的疑惑。
from orientationchange-fix.
from orientationchange-fix.
from orientationchange-fix.
好吧!其实我不建议你在mobile上使用$(window).innerHeight()获取浏览器visual viewport的高度。因为不靠谱的,每个浏览器给出值都不一样,特别是国内,如浏览器UC,搜狗。他们给的值会减掉工具栏(定栏或底栏)的高度。至于你说高度有时不正确,我想到的可能与工具栏有关吧。当然也有一些隐藏工具栏技巧(不过貌似对国内一些浏览器不好使):
function hideURLbar() {
if (window.location.hash.indexOf('#') == -1) {
window.scrollTo(0, 1);
}
}
if (navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('Android') != -1) {
addEventListener("load", function() {
setTimeout(hideURLbar, 0);
}, false);
}
参考文章:http://atlchris.com/1847/quick-tip-hide-mobile-web-browser-address-bar-improved/
之前做横竖屏适应了解一点,希望对你有帮忙。至于其他原因我就不了解了-。-
from orientationchange-fix.
from orientationchange-fix.
你们旋转屏幕的时候例子没出现死循环递归吗
from orientationchange-fix.
其实这个问题,我在IOS里碰到过好多次,尤其是在用微信打开某个页面时:
该问题为客户端问题,和JavaScript无关,更和各种轮子无关
350*588的手机屏幕,横屏时,获取高度约为300;然后横屏转竖屏的一瞬间,屏幕转换事件触发了(无论是原生orientationchange事件,还是原生resize事件),但那一瞬间获取的高度仍然是300
在适当的延迟几百毫秒之后,才能正确获得旋转之后的高度(大约500)个人在想,是否可以单独针对这种情况,将旋转事件event,切分为eventStart和eventEnd,eventEnd代表横竖比已经切换完毕
这个问题我也发现了,ios微信客户端读window.innerHeight在第一次横竖屏切换的时候是正确的,然而第二次切换的时候innerHeight要过一定的延时才能正确更新、
from orientationchange-fix.
原生resize事件监听的是屏幕尺寸的变化,并不会监听innerHeight值的变化,所以在改变横竖屏的那一刻,值是不对的,几秒之后,值就对了,所以建议在updata里面监听innerHeight值的改变会比使用sesize要好。
from orientationchange-fix.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orientationchange-fix.