【问题标题】:How to customize the jQuery Mobile Navbar?如何自定义 jQuery Mobile 导航栏?
【发布时间】:2017-05-25 18:49:39
【问题描述】:

我正在尝试在屏幕底部为手机应用制作导航栏,类似于:https://dribbble.com/shots/3418526-Poppinz-Navbar-Animation 其中添加按钮是一个圆形图标,比其他选项卡略高。

仅使用 HTML、CSS 和 jQuery Mobile 是否可以做到这一点?

我还在学习编码,我必须使用 jQuery Mobile。我怎样才能做到这一点?

.nav-icons .ui-btn {
  padding-top: 50px !important;
  font-family: 'lato', sans-serif !important;
  font-size: 18px !important;
  font-weight: 100 !important;
  text-shadow: none !important;
  color: #FFF !important;
  background-color: #03314c !important;
  box-shadow: none !important;
  -moz-box-shadow: none !important;
  -webkit-box-shadow: none !important;
  -webkit-border-radius: 0 !important;
  border-radius: 0 !important;
  border: 0px !important;
}

.nav-icons .ui-btn:after {
  width: 36px;
  height: 36px;
  margin-left: -15px;
  box-shadow: none;
  -moz-box-shadow: none;
  -webkit-box-shadow: none;
  -webkit-border-radius: 0;
  border-radius: 0;
  border: 0px;
}

.ui-btn:active {
  background-color: #004d78 !important;
}

#home:after {
  background: url("icons/home/home_white_fillmdpi.png") 50% 50% no-repeat;
  background-size: 36px 36px;
  font-weight: 100;
}

#two:after {
  background: url("icons/clock/clock_white_fillmdpi.png") 50% 50% no-repeat;
  background-size: 36px 36px;
}

#three:after {
  position: relative;
  display: flex !important;
  justify-content: space-between !important;
}

#four:after {
  background: url("icons/dollarsign/dollarsign_white fillmdpi.png") 50% 50% no-repeat;
  background-size: 36px 36px;
}

#five:after {
  background: url("icons/dotmenu/dotmenu_whitefillmdpi.png") 50% 50% no-repeat;
  background-size: 36px 36px;
}

img {
  max-width: 50px;
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, calc(-40%));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE HTML>
<html>

<head>


  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
  <link rel="stylesheet" href="style.css">
  <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>


</head>

<body>
  <h1>hello</h1>
  <div data-role="footer" class="nav-icons" data-theme="a">

    <div data-role="navbar" class="nav-icons" data-grid="d">
      <ul>
        <li><a href="#" id="home" data-icon="custom">Home</a></li>
        <li><a href="#" id="two" data-icon="custom">2</a></li>
        <li>
          <a href="#" id="three"><img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">3</a>
        </li>
        <li><a href="#" id="four" data-icon="custom">4</a></li>
        <li><a href="#" id="five" data-icon="custom">5</a></li>
      </ul>
    </div>

  </div>

【问题讨论】:

    标签: html css jquery-mobile navbar


    【解决方案1】:

    是的,有很多方法可以做到。一种简单的方法是使用position: absolutetransform: translate() 将一个圆形图标添加到扩展超出父级边界的链接之一。

    body {
      background: #eee;
    }
    nav {
      width: 90%;
      max-width: 600px;
      background: white;
      display: flex;
      justify-content: space-between;
      margin: 3em auto;
      padding: 2em;
    }
    .special {
      position: relative;
    }
    img {
      border-radius: 50%;
      max-width: 50px;
      position: absolute;
      top: 0; left: 50%;
      transform: translate(-50%,calc(-115%));
    }
    <nav>
      <a href="#">link</a>
      <a href="#">link</a>
      <a href="#" class="special"><img src="http://kenwheeler.github.io/slick/img/lazyfonz2.png">i'm special</a>
      <a href="#">link</a>
      <a href="#">link</a>
    </nav>

    【讨论】:

    • 这对我不起作用,因为我使用 jquery mobile 作为导航栏/页脚。
    • @AndreaG 然后包含您正在使用的代码。如果您不包含代码,我们就没有参考,我们所能做的就是猜测。该技术仍然存在。您可以将图像添加到导航元素。这里的标记与我的解决方案 demos.jquerymobile.com/1.2.0/docs/toolbars/docs-navbar.html 中的标记没有太大区别
    • 对不起,我将添加代码。只需要弄清楚如何。
    • 当我将您的代码添加到具有默认 jquery ui JS 和 CSS 的页面时,它根本不会为您的菜单设置样式。请创建一个演示,在您的帖子中重现您当前的布局。
    • 我尝试修复它,我不确定为什么它没有设置样式。当我用 Chrome 打开它时,它会在我的计算机上设置样式。
    【解决方案2】:

    JQM Navbar 小部件正在注入 Grid,但您可以自己为此类网格提供标记。

    这里的棘手部分是从该网格中删除overflow: hidden 样式,然后我们只需要恢复一些顶部和底部填充。当然还有其他方法可以达到同样的效果。

    由于您喜欢尝试使用 jQuery Mobile,我还覆盖了一些其他典型的(恕我直言)过于沉重的 JQM 样式,因此您可以通过评论每种样式来使用它来查看差异。

    .ui-grid-d {
      overflow: visible !important;
    }
    .ui-grid-d div {
      font-weight: normal !important;
      font-family: 'Jura', sans-serif !important;
      font-size: 12px;
    }
    .ui-grid-d a {
      margin: 0;
    }
    .ui-grid-d > .ui-block-a,
    .ui-grid-d > .ui-block-b,
    .ui-grid-d > .ui-block-c,
    .ui-grid-d > .ui-block-d,
    .ui-grid-d > .ui-block-e {
        text-align: center !important;
        background: white;
        padding-top: .3em;
        padding-bottom: .9em;
    }
    .ui-btn-icon-notext.ui-btn-active:after {
      background-color: transparent !important;
    }
    .ui-icon-big {
      height: 52px !important;
      width: 52px !important;
      margin-top: -24px !important;
      border-radius: 26px !important;
    }
    .ui-icon-big:after {
      width: 32px !important;
      height: 32px !important;
      background-size: 22px !important;
      margin-top: -16px !important;
      margin-left: -16px !important;
      //background-color: transparent !important;
    }
    /* jQM no frills */
    .ui-btn,
    .ui-btn:hover,
    .ui-btn:focus,
    .ui-btn:active,
    .ui-btn:visited {
      text-shadow: none !important;
    }
    .ui-focus,
    .ui-btn:focus {
      -moz-box-shadow: none !important;
      -webkit-box-shadow: none !important;
      box-shadow: none !important;
    }
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
      <link href="https://fonts.googleapis.com/css?family=Jura" rel="stylesheet">
      <link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
      <link rel="stylesheet" href="style.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.min.js"></script>
      <script src="script.js"></script>
    </head>
    <body>
      <div data-role="page" id="page-one">
        <div data-role="header">
        </div>
        <div data-role="content">
          <h3>Custom Navbar</h3>
        </div>
        <div data-role="footer" data-position="fixed">
          <div data-role="navbar">
            <div class="ui-grid-d" data-theme="a">
              <div class="ui-block-a">
                <a href="#" class="ui-btn ui-corner-all ui-icon-gear ui-btn-icon-notext ui-btn-active"></a>
                <div>Home</div>
            </div>
            <div class="ui-block-b">
              <a href="#" class="ui-btn ui-corner-all ui-icon-refresh ui-btn-icon-notext"></a>
              <div>History</div>
            </div>
            <div class="ui-block-c">
              <a href="#" class="ui-btn ui-corner-all ui-icon-plus ui-icon-big ui-btn-icon-notext"></a>
              <div>Book</div>
            </div>
            <div class="ui-block-d">
              <a href="#" class="ui-btn ui-corner-all ui-icon-user ui-btn-icon-notext"></a>
              <div>Notifications</div>
            </div>
            <div class="ui-block-e">
              <a href="#" class="ui-btn ui-corner-all ui-icon-tag ui-btn-icon-notext"></a>
              <div>Profile</div>
            </div>
          </div>
        </div>
      </div>
      </div>
    </body>
    </html>

    如果你还需要涟漪效应,你可以在这里找到一个极好的和 JQM 兼容的实现:Ripple effect in Material Design using jQuery and CSS3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 2012-03-12
      相关资源
      最近更新 更多