简体   繁体   中英

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

I'm attempting to bring an iframe into a shaded overlay on top of the current html document. The desire is for the iframe to start hidden. A trigger, like a link, should show the iframe. The code below is almost mirror the code from Jquery docs.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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