简体   繁体   English

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

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

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

I'm attempting to bring an iframe into a shaded overlay on top of the current html document.我正在尝试将 iframe 带入当前 html 文档顶部的阴影覆盖中。 The desire is for the iframe to start hidden.希望 iframe 开始隐藏。 A trigger, like a link, should show the iframe.触发器(如链接)应显示 iframe。 The code below is almost mirror the code from Jquery docs.下面的代码几乎是 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>

I hope it's a simple issue, but I can't see it.我希望这是一个简单的问题,但我看不到。

It turns out that the mobile jQuery library is separate from the one usually used.事实证明,移动 jQuery 库与通常使用的库是分开的。 Simply add the additional mobile library and its dependencies in your code:只需在代码中添加额外的移动库及其依赖项:

<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>

You should also change the protocol of the embedded video from http to https since modern browsers will block insecure http requests.您还应该将嵌入视频的协议从 http 更改为 https,因为现代浏览器将阻止不安全的 http 请求。

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

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