移動端設定了overflow:hidden頁面還會滾動的禁止方法

來源:互聯網
上載者:User
今天在工作中碰到了一個很尷尬的問題,下面這篇文章主要給大家介紹了關於移動端設定了overflow:hidden,但頁面依然還會滾動的禁止方法,文中通過範例程式碼介紹的非常詳細,需要的朋友們可以參考借鑒,下面來一起看看吧。

前言

本文主要給大家介紹了關於在移動端設定了overflow:hidden頁面還會滾動的禁止方法,分享出來供大家參考學習,下面話不多說了,來一起看看詳細的介紹吧。

如果把 overflow:hidden 用在 body 標籤,移動端瀏覽器依然能滾動,因為移動端是基於touch事件,解決方案有兩個。

方法一:

將要隱藏滾動的內容加上一個包裹層p,然後給這個p設定高度為window.height() ,並且 overflow:hidden 就可以解決你的問題。

方法二:

給 body 添加 position:fixed; 樣本:


body { overflow:hidden; position:fixed; left:0; top:0;}
相關文章

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.