jQuery Mobile面板的positionFixed选项
jQuery Mobile是一种基于网络的技术,用于制作可在所有智能手机、平板电脑和台式机上访问的响应式内容。
在这篇文章中,我们将使用jQuery Mobile panel positionFixed选项来设置指定的面板是否有固定位置,以检查即使页面向下滚动,内容是否在视野内。这个选项也允许页面滚动而面板保持固定。当面板在Android应用程序中使用时,建议不要启用这个功能,因为性能和显示问题很差。
语法:
用positionFixed选项初始化面板。
$( ".selector" ).panel({ positionFixed: true });
- 设置positionFixed选项。
$( ".selector" ).panel( "option", "positionFixed", true );
- 获得positionFixed选项。
var theme = $( ".selector" ).panel( "option", "positionFixed" );
CDN链接:首先,添加你的项目需要的jQuery Mobile脚本。
<link rel=”stylesheet” href=”//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css”>
<script src=”//code.jquery.com/jquery-3.2.1.min.js”></script>
<script src=”//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js”></script>
例子:这个例子描述了jQuery Mobile面板的positionFixed选项。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href=
"//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.css">
<script src=
"//code.jquery.com/jquery-3.2.1.min.js">
</script>
<script src=
"//code.jquery.com/mobile/1.5.0-alpha.1/jquery.mobile-1.5.0-alpha.1.min.js">
</script>
</head>
<body>
<center>
<div data-role="page">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h3>jQuery Mobile panel positionFixed Option</h3>
<div role="main">
<a href="#divID" data-role="button"
data-inline="true"
data-icon="bars">GeeksforGeeks</a>
</div>
<div data-role="panel" id="divID" data-theme="b">
<div class="panel-content">
<h3>GeeksforGeeks</h3>
<p>It is a computer science portal.</p>
<a href="#demo-links" data-rel="close"
data-role="button" data-theme="c"
data-icon="delete"
data-inline="true">Close this panel</a>
</div>
</div>
<input type="button" id="Button"
value="Value of the positionFixed option">
<div id="log"></div>
</div>
</center>
<script>
(document).ready(function () {
("#divID").panel({
positionFixed: true
});
("#divID").panel("option", "positionFixed", true);
("#Button").on('click', function () {
var a = ("#divID").panel("option", "positionFixed");
("#log").html(a);
});
});
</script>
</body>
</html>
输出:
jQuery Mobile面板的positionFixed选项