Get width and height of HTML5 Video using native JavaScript

后端 未结 1 1687
名媛妹妹
名媛妹妹 2021-02-10 17:45

I am trying to get width and height of tag, I am using the following markup:

相关标签:
1条回答
  • 2021-02-10 18:23

    This code will give you the dimensions of the video tag (not the dimensions of the video itself)

    var video = document.getElementById("video");
    var videotag_width = video.offsetWidth;
    var videotag_height = video.offsetHeight;
    

    This code will give you the dimensions of the video that is currently playing

    var video = document.getElementById("video");
    var video_height = video.videoHeight;
    var video_width = video.videoWidth;
    
    0 讨论(0)
提交回复
热议问题