콘텐츠의 최대 크기로 iframe을 확장하는 jsFiddle에서이 jQuery 코드를 사용했습니다. 다음 jQuery 코드를 추가 템플릿에서
<article>
<p><iframe width="400" height="400" src="http://www.youtube.com/...."></iframe></p>
</article>
: 포스트에서
당신은이 HTML 코드를 추가합니다.
<script type='text/javascript'>
jQuery(document).ready(function($) {
$(function() {
var $allVideos = $("iframe[src^='http://player.vimeo.com'], iframe[src^='http://www.youtube.com'], object, embed"),
$fluidEl = $("p");
$allVideos.each(function() {
$(this)
// jQuery .data does not work on object/embed elements
.attr('data-aspectRatio', this.height/this.width)
.removeAttr('height')
.removeAttr('width');
});
$(window).resize(function() {
var newWidth = $fluidEl.width();
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.attr('data-aspectRatio'));
});
}).resize();
});
});
</script>
나는 내 Wordpress 사이트에서 코드를 시험해 보았다.
Chrome에서 훌륭하게 작동합니다. Safari 및 Firefox에서 브라우저 호환성에 대한 제안 사항이 있으십니까? – user2132752
저는 javascript에 대한 전문가는 아니지만 Chrome 개발자 도구를 살펴보면 Javascript 오류가 상당히 많이 발생합니다. 처음부터 제거하십시오. 이것을 확인하십시오 : http://stackoverflow.com/questions/7181573/does-javascript-execution-stop-when-an-invalid-line-is-encountered – user850010