2013-02-15 91 views
2

是否可以檢測HTML5視頻元素的寬高比?檢測寬高比--HTML5視頻

我知道視頻會縮小以適合<video>元素的尺寸,但我想要檢測源視頻的縱橫比。

這樣你可以刪除任何黑條。

對不起,我沒有看到這回答其他地方。從另一個StackOverflow的答案

回答

8

粘貼: https://stackoverflow.com/a/4129189/1353189

<video id="foo" src="foo.mp4"></video> 

var vid = document.getElementById("foo"); 
vid.videoHeight; // returns the intrinsic height of the video 
vid.videoWidth; // returns the intrinsic width of the video 

源(HTML5規範):http://www.w3.org/TR/html5/video.html#video

然後可以通過將高度除以寬度計算縱橫比。

+0

完美的作品,謝謝你發現 – 2013-02-15 22:58:27