为了账号安全,请及时绑定邮箱和手机立即绑定

为什么 video.width 是 0 但实际上是 539?

为什么 video.width 是 0 但实际上是 539?

噜噜哒 2021-12-23 16:59:42
这是一张图片并且宽度和高度不是 0,但是当我在控制台中打印它时,它返回 0。、这是我如何打印它的代码:const video = document.getElementById("remoteVideo");video.addEventListener('play', () => {      setInterval(async () => {      console.log(video.width);      console.log(video.height);      }, 100)    });这是完整的html:<!DOCTYPE html><html></html><head>  <meta charset="UTF-8">  <title>Document</title>  <style type="text/css">      html { height: 100%; }      body { height: 100%; margin: 0; background: #111; text-align: center; }      #remoteVideo { height: 70%; margin-top: 5%; background: #000; }      #localVideo { width: 20%; position: absolute; right: 1.1em; bottom: 1em; border: 1px solid #333; background: #000; }      #callButton { position: absolute; display: none; left: 50%; font-size: 2em; bottom: 5%; border-radius: 1em; }  </style>  <script defer src="static/face-api.min.js"></script></head><body>    <video id="localVideo" autoplay muted></video>    <video id="remoteVideo" autoplay></video>    <button id="callButton" onclick="createOffer()">✆</button>    <script src="/socket.io/socket.io.js"></script>    <script defer src="static/script.js"></script></body></html>我究竟做错了什么?
查看完整描述

1 回答

?
慕容3067478

TA贡献1773条经验 获得超3个赞

您可以使用


没有异步的getBoundingClientRect


这是您如何使用https://www.pexels.com/videos/在最小的、可重现的示例中发布您的问题


const video = document.getElementById("remoteVideo");

video.addEventListener('play', () => {

    console.log(video.getBoundingClientRect() );

});

html {

  height: 100%;

}


body {

  height: 100%;

  margin: 0;

  background: yellow;

  text-align: center;

}


#remoteVideo {

  height: 70%;

  margin-top: 5%;

  background: red;

}


#localVideo {

  width: 20%;

  position: absolute;

  right: 1.1em;

  bottom: 1em;

  border: 1px solid #333;

  background: pink;

}


#callButton {

  position: absolute;

  display: none;

  left: 50%;

  font-size: 2em;

  bottom: 5%;

  border-radius: 1em;

}

<video id="localVideo" src="https://player.vimeo.com/external/357005099.sd.mp4?s=a95b2118e2fa52097ad9933b56d50ebcc9f2f1c9&profile_id=139&oauth2_token_id=57447761" autoplay muted>Video</video>

<video id="remoteVideo" autoplay src="https://player.vimeo.com/external/340284081.sd.mp4?s=00350f6e127d8ac3777d74528fa439944f7d9f2c&profile_id=139&oauth2_token_id=57447761">Video</video>

<button id="callButton" onclick="createOffer()">Button ✆</button>


查看完整回答
反对 回复 2021-12-23
  • 1 回答
  • 0 关注
  • 276 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号