jquery 반응형 iframe > IT 기술백서

IT 기술백서

직접 알아내거나 검색하기 귀찮아서 모아 둔 것

JavaScript | jquery 반응형 iframe

본문

[code]

function resizeIframe() {

    const iframes = $('.view-content iframe');

    iframes.each(function (idx, ele) {

        const w = $(ele).width();

        const h = $(ele).height();

        const ratio = h / w * 100;


        $(ele).wrap(`<div style="position:relative; padding-bottom:${ratio}%"></div>`);

        $(ele).css({

            'position': 'absolute',

            'top': '0',

            'left': '0',

            'width': '100%',

            'height': '100%'

        });

    })

}

 

$(document).ready(function() {

    resizeIframe();

});

[/code]

댓글 0개

등록된 댓글이 없습니다.

Menu