javascript - 如何获取视频海报的图像尺寸?
问题描述
如何获取元素中poster
图像的图像尺寸(宽度和高度)?<video poster="…">
jQuery 是可以接受的。
解决方案
如果您的<video>
元素被引用为yourVideo
(例如const yourVideo = document.querySelector("video");
),那么您可以通过该属性获取其poster
URL 。poster
这只是一个图像 URL,因此可以像使用任何图像 URL 一样获取其尺寸:
const poster = Object.assign(new Image(), {
src: yourVideo.poster
});
poster.addEventListener("load", () => console.log(poster.width, poster.height));
推荐阅读
- c# - C#:Math Round() 为不同的小数产生不同的值
- python - 使用预先确定的主题分布初始化 Gensim LDA 模型
- python - 将复选框存储到列表 tkinter
- firebase - 如何通过应用引擎监控firestore并同时执行多个游戏?
- command-line-interface - 如何使用 go lang 模板选项过滤 openshift pod?
- authentication - 为什么 Google Cloud Translate 无法提供持久性 503 服务?
- azure-data-factory-2 - Azure 数据工厂从 URL 保存 CSV
- amazon-web-services - 从另一个 AWS 账户访问 S3 Inventory
- python - 使用 importlib 加载模块时如何允许相对导入
- r - 导入未按逻辑方式排序的数据