【发布时间】:2019-11-11 15:18:14
【问题描述】:
这是一张图片
和宽度和高度不是 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 lang="en"></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>
我做错了什么?
【问题讨论】:
-
你也可以给我们看看你的 HTML 吗?
-
使用 getBoundingClientRect
-
getBoundingClientRect() 有效,非常感谢
标签: javascript html