移動端position:fixed小結

來源:互聯網
上載者:User

標籤:position   absolute   relative   footer   

fixed在移動端是個坑,相容性就是個極品。

ios的bug比較多,詳見https://github.com/maxzhang/maxzhang.github.com/issues/2

作者建議我們安卓還是使用fixed比較好,ios用iscroll來填坑比較好


關於fixed一些小細節還可以參考一下:

https://github.com/maxzhang/maxzhang.github.com/issues/11

裡面提及到的例子:http://output.jsbin.com/omaCOSir/latest

布局的方法是:

<header class="relative">    <div class="fixed">...</div></header><div class="main"></div><footer>    <div class="fixed">...</div></footer>

有一點不明白的是為什麼要用relative來表示header和footer,雖然真正起作用的是fixed。


如果fixed不支援,有一個我個人認為很山寨的方法,就是用absolute,onscroll的時候計算$(window).scrollTop(),可是這個方法首先在展示的時候不完美,一點是有時候的計算是小數點,所以會空出1個px(當然可以-1px來補),還有就是頻繁計算和重新渲染。


安卓4.4.2有些機子是可以支援的,有些的支援度不夠,渲染的時候不給力,但勉強可以渲染,開啟硬體加速更佳


沒有比較好的辦法,不過有無敵方法:iScroll

移動端position:fixed小結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.