- 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.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src = "https://code.jquery.com/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
廣告