HTML5 Video dimensions in Safari IOS

前端 未结 5 953
渐次进展
渐次进展 2021-01-06 01:50

I\'m building a website for a client who\'s majority of content is video. I\'m using the HTML5 video element to display the content but have problems when it comes to Safari

5条回答
  •  梦谈多话
    2021-01-06 02:07

    Via CSS, try giving it a width of 100% and a height of auto.

    EDIT In this case you need to use JavaScript to wait until the video has loaded the metadata and then read and set the width and height, for example:

    var v = document.getElementById('myVideo');
    v.addEventListener('loadedmetadata', function(e) {
       this.width = this.videoWidth;
       this.height = this.videoHeight;
    }, false);
    

    I haven't exactly tested this but it should lead you on the right track.

提交回复
热议问题