繁体   English   中英

Jquery iframe 弹出式覆盖 - iframe 未隐藏,触发器未带来屏幕覆盖

[英]Jquery iframe popup overlay - iframe not hidden, trigger not bringing screen overlay

按照这里的演示: https://demos.jquerymobile.com/1.2.1/docs/pages/popup/popup-iframes.html

我正在尝试将 iframe 带入当前 html 文档顶部的阴影覆盖中。 希望 iframe 开始隐藏。 触发器(如链接)应显示 iframe。 下面的代码几乎是 Jquery 文档中的代码的镜像。

<!DOCTYPE html>
<html>
  <head>
    <title>testmessage</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>
// popup examples
$( document ).on( "pageinit", function() {

   function scale( width, height, padding, border ) {
      var scrWidth = $( window ).width() - 30,
         scrHeight = $( window ).height() - 30,
         ifrPadding = 2 * padding,
         ifrBorder = 2 * border,
         ifrWidth = width + ifrPadding + ifrBorder,
         ifrHeight = height + ifrPadding + ifrBorder,
         h, w;

      if ( ifrWidth < scrWidth && ifrHeight < scrHeight ) {
         w = ifrWidth;
         h = ifrHeight;
      } else if ( ( ifrWidth / scrWidth ) > ( ifrHeight / scrHeight ) ) {
         w = scrWidth;
         h = ( scrWidth / ifrWidth ) * ifrHeight;
      } else {
         h = scrHeight;
         w = ( scrHeight / ifrHeight ) * ifrWidth;
      }

      return {
         'width': w - ( ifrPadding + ifrBorder ),
         'height': h - ( ifrPadding + ifrBorder )
      };
   };

   $( ".ui-popup iframe" )
      .attr( "width", 0 )
      .attr( "height", "auto" );

   $( "#popupVideo" ).on({
      popupbeforeposition: function() {
         // call our custom function scale() to get the width and height
         var size = scale( 497, 298, 15, 1 ),
            w = size.width,
            h = size.height;

         $( "#popupVideo iframe" )
            .attr( "width", w )
            .attr( "height", h );
      },
      popupafterclose: function() {
         $( "#popupVideo iframe" )
            .attr( "width", 0 )
            .attr( "height", 0 );
      }
   });

});
</script>
<style>
iframe { border: none; }

#popupPanel-popup {
   right: 0 !important;
   left: auto !important;
}
#popupPanel {
   width: 200px;
   border: 1px solid #000;
   border-right: none;
   background: rgba(0,0,0,.5);
   margin: -1px 0;
}
#popupPanel .ui-btn {
   margin: 2em 15px;
}
</style>

  </head>

  <body>

    <h1>testmessage</h1>
    <hr>
      <a href="#popupVideo" data-rel="popup" data-position-to="window" data-role="button" data-theme="b" data-inline="true">Launch Iframe Overlay</a>
      <div data-role="popup" id="popupVideo" data-overlay-theme="a" data-theme="d" data-tolerance="15,15" class="ui-content">
         <iframe src="http://player.vimeo.com/video/41135183?portrait=0" width="497" height="298" seamless></iframe>
      </div>

  </body>
</html>

我希望这是一个简单的问题,但我看不到。

事实证明,移动 jQuery 库与通常使用的库是分开的。 只需在代码中添加额外的移动库及其依赖项:

<link rel="stylesheet" href="https://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.css" />
<script src="https://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="https://code.jquery.com/mobile/1.2.0-alpha.1/jquery.mobile-1.2.0-alpha.1.min.js"></script>

您还应该将嵌入视频的协议从 http 更改为 https,因为现代浏览器将阻止不安全的 http 请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM