Skip to content

Instantly share code, notes, and snippets.

@timn5835
Last active January 11, 2021 16:32
Show Gist options
  • Save timn5835/70382553c78f46b92933fcc1d7609c98 to your computer and use it in GitHub Desktop.
Save timn5835/70382553c78f46b92933fcc1d7609c98 to your computer and use it in GitHub Desktop.
[Vimeo API] Play/pause vimeo embeds on modal open/close #js #bootstrap #vimeo #modals
/*
Add this to functions.php
function enqueue_scripts() {
wp_enqueue_script( 'vimeo-api', '//player.vimeo.com/api/player.js', true);
}
*/
// Vimeo API Documentation: https://developer.vimeo.com/api/reference
// Pause video on modal close
var player = new Vimeo.Player($('#videoModal iframe'));
$('#videoModal.modal').on('hidden.bs.modal', function(e) {
if (player != null) {
player.pause();
}
});
// Play video on modal open
$('button[data-target="#videoModal"]').on('click', function(e) {
if (player != null) {
player.play();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment