如何检测 jQuery 移动设备中全屏工具栏的切换?
How to detect toggling of the fullscreen-toolbar in jQuery Mobile?
我有一个带有固定全屏工具栏的 jQuery 移动页面,其中启用了 data-tap-toggle
。
我在工具栏正下方放置了一个横幅,当工具栏隐藏时,它应该向上滑动,当工具栏显示时,它应该向下滑动。
jQuery Mobile 通过应用和删除 ui-fixed-hidden
class 来切换 toolbar
- 遗憾的是,我在 [=14= 的文档中找不到] 小部件任何 toggle
、hide
或 show
事件。
如何检测 toolbar
何时切换,以重新定位我的横幅?
.banner {
position: fixed;
background-color: darkseagreen;
top: 46px;
min-height: 48px;
width: 100%;
text-align: center;
line-height: 48px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
</head>
<body>
<div data-role="page" id="page-one">
<div data-theme="a" data-role="header" data-position="fixed" data-fullscreen="true">
<h1>First Page</h1>
</div>
<div data-role="content">
<div class="banner">call-to-action</div>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" data-fullscreen="true">
<h3>Footer</h3>
</div>
</div>
</body>
</html>
解决方案 1:
扩展 mobile.toolbar
小部件。
$.widget("mobile.toolbar", $.mobile.toolbar, {
toggle: function() {
this[this._visible ? "hide" : "show"]();
if (this._visible) {
/* visible */
} else {
/* hidden */
}
}
});
解决方案 2:
收听动画结束事件。
$(document).on("pagecreate", function() {
$(".ui-header").on("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function(e) {
/* do something */
});
});
我有一个带有固定全屏工具栏的 jQuery 移动页面,其中启用了 data-tap-toggle
。
我在工具栏正下方放置了一个横幅,当工具栏隐藏时,它应该向上滑动,当工具栏显示时,它应该向下滑动。
jQuery Mobile 通过应用和删除 ui-fixed-hidden
class 来切换 toolbar
- 遗憾的是,我在 [=14= 的文档中找不到] 小部件任何 toggle
、hide
或 show
事件。
如何检测 toolbar
何时切换,以重新定位我的横幅?
.banner {
position: fixed;
background-color: darkseagreen;
top: 46px;
min-height: 48px;
width: 100%;
text-align: center;
line-height: 48px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
</head>
<body>
<div data-role="page" id="page-one">
<div data-theme="a" data-role="header" data-position="fixed" data-fullscreen="true">
<h1>First Page</h1>
</div>
<div data-role="content">
<div class="banner">call-to-action</div>
</div>
<div data-theme="a" data-role="footer" data-position="fixed" data-fullscreen="true">
<h3>Footer</h3>
</div>
</div>
</body>
</html>
解决方案 1:
扩展 mobile.toolbar
小部件。
$.widget("mobile.toolbar", $.mobile.toolbar, {
toggle: function() {
this[this._visible ? "hide" : "show"]();
if (this._visible) {
/* visible */
} else {
/* hidden */
}
}
});
解决方案 2:
收听动画结束事件。
$(document).on("pagecreate", function() {
$(".ui-header").on("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function(e) {
/* do something */
});
});