2016-08-24 30 views
2

我正在製作angular-js和cordova的移動項目。我想添加一個功能,我想要顯示視頻,它應該旋轉自己,當我旋轉設備風景或肖像,但我有一個限制,在應用程序打開我開始使用lockOrientation(肖像),所以我不想旋轉任何頁面到風景,我只想旋轉視頻不屏幕。我試圖檢測旋轉與視頻定位javascript

window.addEventListener("orientationchange", function() { 
     alert("the orientation of the device is now " + screen.orientation.angle); 
    }); 

和在CSS我可以旋轉視頻下面的代碼。

transform:rotate(90deg); 

我的問題是如何檢測設備的方向,而使用lockOrientation?可能嗎?因爲我無法解鎖方向。我是一名學生,我對這個環境很陌生。

回答

1

我與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); 

隨着加速度我檢測到的設備運動的同時,裝置被鎖定以縱向模式和作出如果檢查,以檢測所述設備處於縱向模式或風景模式。