Skip to content

Instantly share code, notes, and snippets.

@amol-anand
Last active February 26, 2024 20:02
Show Gist options
  • Save amol-anand/f797e6ab9513898e132987dabcaca262 to your computer and use it in GitHub Desktop.
Save amol-anand/f797e6ab9513898e132987dabcaca262 to your computer and use it in GitHub Desktop.
Video Autoplay code snippet
const video = document.createElement('video');
video.muted = true; // exactly this way, otherwise it won't play in chrome. Thanks, @msagolj for the tip!
video.toggleAttribute('autoplay', true);
video.toggleAttribute('loop', true);
video.toggleAttribute('playsinline', true);
const source = document.createElement('source');
source.setAttribute('src', entry[2]);
source.setAttribute('type', 'video/mp4');
video.append(source);
slide.append(video);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment