Created
May 30, 2019 07:35
-
-
Save ivan-kalachikov/29bc6dddcdf64682135f23dae78a25c3 to your computer and use it in GitHub Desktop.
Magnific popup autoplay youtube video
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
<a href="https://www.youtube.com/watch?v=ZNr5KdZNThQ" class="btn play-video youtube">Play</a> | |
$( '.banner .play-video.youtube' ).magnificPopup( { | |
type: 'iframe', | |
iframe: { | |
markup: '<div class="mfp-iframe-scaler">'+ | |
'<div class="mfp-close"></div>'+ | |
'<iframe class="mfp-iframe" frameborder="0" allowfullscreen allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"></iframe>'+ | |
'</div>', | |
patterns: { | |
youtube: { | |
index: 'youtube.com/', // String that detects type of video (in this case YouTube). Simply via url.indexOf(index). | |
id: 'v=', // String that splits URL in a two parts, second part should be %id% | |
// Or null - full URL will be returned | |
// Or a function that should return %id%, for example: | |
// id: function(url) { return 'parsed id'; } | |
src: 'https://www.youtube.com/embed/%id%?autoplay=1' // URL that will be set as a source for iframe. | |
} | |
}, | |
srcAction: 'iframe_src', | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment