【问题标题】:How to detect toggling of the fullscreen-toolbar in jQuery Mobile?如何检测 jQuery Mobile 中全屏工具栏的切换?
【发布时间】:2017-08-20 19:34:06
【问题描述】:

我有一个带有固定全屏工具栏的 jQuery Mobile 页面,其中启用了data-tap-toggle

我在工具栏的正下方放置了一个横幅,当工具栏隐藏时它应该向上滑动,当工具栏显示时它应该向下滑动。

jQuery Mobile 通过应用和删除ui-fixed-hidden 类来切换toolbar - 遗憾的是,我在toolbar 小部件的文档中找不到任何togglehideshow 事件那个。

我如何检测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>

【问题讨论】:

    标签: javascript jquery jquery-mobile


    【解决方案1】:

    解决方案 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 */
      });
    });
    

    Demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多