Created
February 22, 2017 03:50
-
-
Save alesanabriav/3046f5a3255ed6b217802ba70c67b2e7 to your computer and use it in GitHub Desktop.
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
<script> | |
var modal = $('.modal'); | |
$('.videos__open-modal').on('click', function(e) { | |
e.preventDefault(); | |
var src = $(this).attr('href') + '?autoplay=1'; | |
modal.find('iframe').attr('src', src); | |
modal.find('.iframe-container').css({'padding-bottom': '56.25%'}); | |
modal.addClass('modal--show'); | |
$(document.body).addClass('modal-open'); | |
}); | |
$('.modal__close').on('click', function(e) { | |
e.preventDefault(); | |
modal.find('iframe').attr('src', ''); | |
modal.find('.iframe-container').css({'padding-bottom': '0'}); | |
modal.removeClass('modal--show'); | |
$(document.body).removeClass('modal-open'); | |
}); | |
$(document).on('keyup', function(e) { | |
modal.find('iframe').attr('src', ''); | |
if(e.keyCode === 27) { | |
modal.find('iframe').attr('src', ''); | |
modal.find('.iframe-container').css({'padding-bottom': '0'}); | |
modal.removeClass('modal--show'); | |
$(document.body).removeClass('modal-open'); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment