Last active
January 11, 2021 16:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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