Ser*_*ets 5 jquery screen-orientation dom-events ios
Orientationchange事件不会在 iOS 设备上触发。在台式机和 Android 设备上一切正常,但操作系统设备不支持此事件。如何确定 iOS 设备上的屏幕方向变化?
小智 5
这确实是老事了,但最近发生在我身上。
我让它工作:
window.addEventListener('resize', functionName)
function functionName() {
if(window.innerWidth > window.innerHeight) {
//then do stuff
}
if(window.innerWidth < window.innerHeight) {
//then do other stuff
}
}Run Code Online (Sandbox Code Playgroud)
我在这篇文章中得到了答案 /sf/answers/687713631/
但如果您仍然没有获得方向值,请尝试以下操作:
function onOriChange() {
if(!window.orientation){
if(window.innerWidth > window.innerHeight){
alert('landscape');
}else{
alert('portrait');
}
}
}
window.addEventListener('orientationchange', onOriChange);
// Initial execution if needed
onOriChange();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7553 次 |
| 最近记录: |