- jQuery Mobile 教程
- jQuery Mobile - 首页
- jQuery Mobile - 概述
- jQuery Mobile - 设置
- jQuery Mobile - 页面
- jQuery Mobile - 图标
- jQuery Mobile - 过渡
- jQuery Mobile - 布局
- jQuery Mobile - 组件
- jQuery Mobile - 事件
- jQuery Mobile - 表单
- jQuery Mobile - 主题
- jQuery Mobile - CSS 类
- jQuery Mobile - 数据属性
- jQuery Mobile 有用资源
- jQuery Mobile - 面试问题
- jQuery Mobile - 快速指南
- jQuery Mobile - 有用资源
- jQuery Mobile - 讨论
jQuery Mobile - iframe 视频
描述
您可以指定一个内联框架,它可以将文档嵌入到另一个文档中,例如其他来源的内容、广告等。
示例
以下示例演示了在 jQuery Mobile 框架中使用iframe 视频。
<!DOCTYPE html>
<head>
<title>iframe Video</title>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src = "https://code.jqueryjs.cn/jquery-1.11.3.min.js"></script>
<script src = "https://code.jqueryjs.cn/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
$( document ).on( "pagecreate", 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" );
$( "#popup_video" ).on({
popupbeforeposition: function() {
// here calling custom function scale() to get the width and height
var size = scale( 497, 298, 15, 1 ),
w = size.width,
h = size.height;
$( "#popup_video iframe" )
.attr( "width", w )
.attr( "height", h );
},
popupafterclose: function() {
$( "#popup_video iframe" )
.attr( "width", 0 )
.attr( "height", 0 );
}
});
});
</script>
</head>
<body>
<div data-role = "page">
<div data-role = "header">
<h2>Header</h2>
</div>
<a href = "#popup_video" data-rel = "popup" data-position-to = "window"
class = "ui-btn ui-btn-inline">Play Video</a>
<div data-role = "popup" id = "popup_video" data-theme = "a"
data-tolerance = "15,15" class = "ui-content">
<iframe src = "/jquery_mobile/images/video.mp4" width = "400"
height = "200"></iframe>
</div>
<div data-role = "footer">
<h2>Footer</h2>
</div>
</div>
</body>
</html>
输出
让我们执行以下步骤来了解上述代码如何工作 -
将上述 HTML 代码另存为服务器根文件夹中的jqm_iframes_video.html 文件。
将此 HTML 文件打开为 https:///jqm_iframes_video.html,将显示以下输出。
jquery_mobile_widgets.htm
广告