Skip to content

Instantly share code, notes, and snippets.

@alesanabriav
Created February 24, 2017 16:29
Show Gist options
  • Save alesanabriav/1df2ef842a3e815ec25af36914d76354 to your computer and use it in GitHub Desktop.
Save alesanabriav/1df2ef842a3e815ec25af36914d76354 to your computer and use it in GitHub Desktop.
<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);
var h = $(window).height();
modal.find('.iframe-container').css({'height': h});
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({'height': '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({'height': '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