-
-
Save gabouh/94fb7383d9cce62b724a5a2d5e1d5d6d to your computer and use it in GitHub Desktop.
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
This file contains hidden or 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
| /** | |
| * Stop an iframe or HTML5 <video> from playing | |
| * @param {Element} element The element that contains the video | |
| */ | |
| var stopVideo = function ( element ) { | |
| var iframe = element.querySelector( 'iframe'); | |
| var video = element.querySelector( 'video' ); | |
| if ( iframe ) { | |
| var iframeSrc = iframe.src; | |
| iframe.src = iframeSrc; | |
| } | |
| if ( video ) { | |
| video.pause(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment