2015-03-13 57 views
0

在我的頁面中,我有一個ons-toolbar頂部和一個ons-list在頁面中。第一個列表項包含一個搜索框,當用戶向下滾動列表時,搜索框將與其他元素一起上升,是否有任何方法可以使搜索框粘貼到頁面頂部或工具欄底部?搜索框如何粘在onsen-ui的工具欄上?

回答

1

添加到您的CSS文件:

ons-toolbar ~ .page__content{ 
    margin-top: 45px; 
} 
.search-bar { 
    width: 100%; 
    position: fixed; 
    display: block; 
    margin-top: -45px; 
} 
.after-search-bar { 
    margin-top: -10px; 
} 

你的HTML應該是這樣的

<ons-page> 

    <ons-toolbar> 
      <!--your tool bar--> 
    </ons-toolbar> 
    <div class="search-bar"> 
     <input type="search" class="search-input" style="width: 96%; margin: 6px auto 6px auto;" placeholder="Search">  
    </div> 

    <div class="after-search-bar"> 
     <ons-list> 
      <ons-list-item> 
       <!--your list items--> 
      </ons-list-item> 
     </ons-list> 
    </div> 

</ons-page> 
+0

謝謝,但它並沒有解決問題,搜索欄DIV枝頂端但是當我滾動div的內容(即搜索框)將與其他內容一起移動 – RezaRahmati 2015-03-13 10:16:52

+0

嗯你是什麼意思的「div(即搜索框)」的內容?我測試了上面的代碼,並且當列表內容滾動時,搜索欄粘貼到頂部。 – Tamura 2015-03-18 03:55:12

+0

經測試的示例:http://codepen.io/anon/pen/emQbxa – Tamura 2015-03-18 04:27:39

相關問題