Seb*_*Seb 5 javascript mobile responsive
我想在chrome中使用Js中的API屏幕。
if ( navigator.userAgent.match( /(android|iphone)/gi ) ) {
if ( 'orientation' in screen ) {
//console.log( '// API supported, yeah!' );
//console.log( 'new orientation is ', screen.orientation );
screen.lockOrientation( 'landscape' );
} else {
console.log( '// API not supported ' );
}
} else {
//alert('none');
}
Run Code Online (Sandbox Code Playgroud)
我的错误js:捕获了TypeError:screen.lockOrientation不是函数
/ *其他* /
if ( navigator.userAgent.match( /(android|iphone)/gi ) ) {
if ( 'orientation' in screen ) {
let locOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;
locOrientation('landscape');
console.log( '// API supported, yeah!' , locOrientation);
console.log( 'new orientation is ', screen.orientation );
//screen.lockOrientation( 'landscape' );
} else {
console.log( '// API not supported ' );
}
} else {
//alert('none');
}
Run Code Online (Sandbox Code Playgroud)
我的错误js:locOrientation不是函数
更新:20/04/2017->使用Javascript,我们无法使用导航器锁定方向。
这是因为lockOrientation仍带有前缀。请参阅此 MDN文章中的[2]脚注。另外,在Chrome中,它位于下方orientation.lock。请参阅MDN文章中的[1]脚注。
locOrientation = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation || screen.orientation.lock;
locOrientation('landscape');
Run Code Online (Sandbox Code Playgroud)
请注意,并非所有浏览器都具有此功能。locOrientation使用前请检查是否已设置。
编辑:将较新的添加orientation.lock到示例。
| 归档时间: |
|
| 查看次数: |
6011 次 |
| 最近记录: |