2017-05-25 65 views
1

我正在嘗試爲屏幕底部的手機應用製作導航欄,類似於以下內容:https://dribbble.com/shots/3418526-Poppinz-Navbar-Animation 其中,添加按鈕是一個圓形圖標,比其他選項卡高一點。如何自定義jQuery Mobile Navbar?

只有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>

回答

0

呀有一堆的,你能做到這一點的方式。一個簡單的方法是使用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>

+0

這並沒有爲我工作,因爲我使用用於導航欄/頁腳的jquery移動版。 –

+0

@AndreaG然後包含您正在使用的代碼。如果你不包括代碼,我們沒有參考,我們所能做的只是猜測。該技術仍然存在。您可以將圖像添加到導航元素。這裏的標記與我在解決方案中的標記沒有太大區別https://demos.jquerymobile.com/1.2.0/docs/toolbars/docs-navbar.html –

+0

對不起,我將添加代碼。只需要弄清楚如何。 –

0

的JQM導航欄widget被注入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