获取<video>的原始尺寸

Pau*_*der 5 size video jquery html5 resize

我正在尝试提供视频和图片的列表,将每个图片和图片的大小调整为相同的大小以便于观看。

当用户单击其中一个时,应将其调整为原始大小(或最大为边界框的大小)

我的问题是:如何获得视频的原始尺寸?

对于图像,

var img = new Image();
img.src= $(event.target).attr("src");
img.width   //this is the width
img.height  //this is the height
Run Code Online (Sandbox Code Playgroud)

奇迹般有效。

但是我找不到一种方法来做同样的事情<video>。有没有?

我了解加载元数据有一些问题,但是视频已经加载完毕,我只想将其调整为原始大小(好吧,我不会在调整大小时延迟加载它们的问题,但是我想这很费力)

是否有可能做到这一点?如果是这样,怎么办?首选jQuery。

解:

var video = $(event.target);
var width = video[0].videoWidth;
Run Code Online (Sandbox Code Playgroud)

Amr*_*Amr 5

您可以使用本机 Javascript 来做到这一点:

var video = $("#myvideo" ); //JQuery selector 
video[0].videoWidth; //get the original width
video[0].videoHeight; //get the original height
Run Code Online (Sandbox Code Playgroud)

也想了解一下:

video[0].width; //get or set width for the element in DOM
video[0].height; //get or set height for the element in DOM
Run Code Online (Sandbox Code Playgroud)

有关更多信息,您可以查看 W3 中的链接: videoWidthvideoHeight