javascript - Jquery iframe 弹出覆盖 - iframe 未隐藏,触发器未带来屏幕覆盖
问题描述
按照这里的演示: 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 请求。
推荐阅读
- database - 无法让加拿大邮政编码工作和省全部大写
- python - 熊猫:“丢失与 MySQL 服务器的连接”“系统错误:32 断管”
- javascript - 如何使用双引号删除访问 JS 对象属性
- php - 数据表:addColumn 仅发送文本
- sql - 这个 sqlite 代码的语法有什么问题?
- apache-spark - 为什么单元素RDD中有这么多分区
- html - 为什么在缩放的 html5 画布中可以看到工件?
- rest - Node Js Restapi - 在 Flutter 中调用 Post 方法不起作用
- c++ - 如何通过 malloc 为队列数组分配内存?
- c++ - 由于加号或减号,if/else 语句输出未显示正确消息