모바일 iframe

모바일 iframe

QA

모바일 iframe

본문

모바일에서 iframe으로  youtube 를 넣으면 

모바일에서 넘치는? 상황이 많아서 

 

 

/* 제품 상세내에 유튜브 */

.youtube_video {margin-top:20px;position: relative;width: 100%;padding-bottom: 56.25%;}

.youtube_video iframe {position: absolute;width: 100%;height: 100%;left:0;top:0}

 

이렇게 해서 

되기는 하는데...

 

제가 올릴때는 괜찮은데 고객들이 

올릴경우에는 <div class="youtube_video"><iframe~~~

올릴수 없으니 ㅠㅠㅠ

 

뭔가 해결방법이 없을까요?ㅜ

이 질문에 댓글 쓰기 :

답변 1

자문 자답



$(document).ready(function() {
   if(typeof YOUTUBE_VIDEO_MARGIN == 'undefined') {
      YOUTUBE_VIDEO_MARGIN=5;
   }
   $('iframe').each(function(index,item) {
      if($(item).attr('src').match(/(https?:)?\/\/www\.youtube\.com/)) {
         var w=$(item).attr('width');
         var h=$(item).attr('height');
         var ar = h/w*100;
         ar=ar.toFixed(2);
         //Style iframe
         $(item).css('position','absolute');
         $(item).css('top','0');
         $(item).css('left','0');
         $(item).css('width','100%');
         $(item).css('height','100%');
         $(item).css('max-width',w+'px');
         $(item).css('max-height', h+'px');
         $(item).wrap('<div style="max-width:'+w+'px;margin:0 auto; padding:'+YOUTUBE_VIDEO_MARGIN+'px;" />');
         $(item).wrap('<div style="position: relative;padding-bottom: '+ar+'%; height: 0; overflow: hidden;" />');
      }
   });
});

답변을 작성하시기 전에 로그인 해주세요.
전체 59,514
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT