我正在使用 angular-js 和 cordova 制作一个移动项目。我想添加一个我想显示视频的功能,当我将设备旋转为横向或纵向时它应该自动旋转,但我有一个限制,在应用程序打开的开始我使用 lockOrientation(portrait) 所以我不想将任何页面旋转为横向,我只想旋转视频而不是屏幕。我尝试用
检测旋转 window.addEventListener("orientationchange", function() {
alert("the orientation of the device is now " + screen.orientation.angle);
});
在 css 中,我可以在代码下方旋转视频。
transform:rotate(90deg);
我的问题是如何在使用 lockOrientation 时检测设备的方向?是否可以?因为我无法解锁方向。我是一名学生,我是这个环境的新手。
最佳答案
我用 DeviceMotion 插件解决了 https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device-motion/
function onSuccess(acceleration) {
alert('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
}
function onError() {
alert('onError!');
}
var options = { frequency: 3000 }; // Update every 3 seconds
var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
当设备以纵向模式锁定时,我通过加速检测到设备运动,并检查检测设备是处于纵向模式还是横向模式。
关于javascript - 视频方向javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39117870/