Skip to content

JS 创建 video 元素

Published: at 07:49 PMSuggest Changes

使用 js 来创建 video

const video = document.createElement('video');

// 👇️ Local file
// video.src = 'video.mp4';

// 👇️ Remote file
video.src =
  'https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4';

video.poster =
  'https://peach.blender.org/wp-content/uploads/title_anouncement.jpg?x11217';

video.autoplay = false;
video.controls = true;
video.muted = false;
video.height = 240; // 👈️ in px
video.width = 320; // 👈️ in px

const box = document.getElementById('box');

box.appendChild(video);

参考文章


Previous Post
JS input 上传文件只能上传一次问题解决
Next Post
JS 点击按钮上传文件