Last active
April 5, 2020 07:00
-
-
Save naokazuterada/9a738fdf1160b5385d615ec472880792 to your computer and use it in GitHub Desktop.
Youtubeなどのiframeをアスペクト比維持しつつリサイズするスクリプト(required jquery)
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
const resizeIframeWithKeepingAspectRatio = function () { | |
$('iframe').each(function () { | |
const me = $(this); | |
if (/(youtube\.com|vimeo\.com)/.test(me.attr('src'))) { | |
const height = me.width() * (me.attr('height') / me.attr('width')); | |
me.css('height', `${height}px`); | |
} | |
}); | |
}; | |
$(window).on('resize', resizeIframeWithKeepingAspectRatio); | |
resizeIframeWithKeepingAspectRatio(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment