ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 아이프레임 높이 자동조절
    JAVASCRIPT 2020. 9. 3. 10:21

    <script type="text/javascript">

    // iframe resize

    function autoResize(i)

    {

        var iframeHeight=

        (i).contentWindow.document.body.scrollHeight;

        (i).height=iframeHeight+20;

    }

    </script>

    문서의 <iframe> 코드에 포함되어야 할 스크립트.

     

    <iframe src="#iframeUrl" onload="autoResize(this)" scrolling="no" frameborder="0"></iframe>

     

     

    <div class="videoContainer" style="width:70%;margin:0 auto;">

            <iframe width="<?=$view[wr_9];?>" height="600" src="https://www.youtube.com/embed/<?=$view[wr_1]?>?rel=0<?=$autop?><?=$loopp?>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

            </div>

        

        <script type="text/javascript">

          $(window).resize(function(){resizeYoutube();});

          $(function(){resizeYoutube();});

          function resizeYoutube()

          {

                $("iframe").each(function(){

                       if( /^https?:\/\/www.youtube.com\/embed\//g.test($(this).attr("src")) )

                       {

                             $(this).css("width","100%");

                             $(this).css("height",Math.ceil( parseInt($(this).css("width")) * 480 / 854 ) + "px");

                       }

                 });

           }

          </script>

     

    'JAVASCRIPT' 카테고리의 다른 글

    dateformat yymmdd to yy-mm-dd  (0) 2020.09.03
    부분데이터 리로드  (0) 2020.07.15
    오브젝트 찍기  (0) 2020.07.15
    javascript json 배열 리턴 값 받기  (0) 2020.07.14
    javascript 함수 자동호출  (0) 2020.07.14

    댓글

Designed by Tistory.