移動端body跟著模態框一起滑動問題

來源:互聯網
上載者:User

標籤:isp   pos   一起   rgba   position   rgb   刪掉   ack   mask   

 遇到了一個問題,是點選連結出現彈框,彈框裡面的內容是可以滑動的,結果我滑動的時候發現下面的body也跟著一起滑動,先看一下代碼。

彈框的 HTML:

<div class="mask">    <div class="reserve">        <span class="close">X</span>        <div class="title">title</div>        <div class="content">      //很多內容        </div>    </div></div>

 

彈框的 CSS :

.mask {    position: fixed;    top: 0;    left: 0;    width: 100%;    height: 100%;    display: none;    z-index: 990;    background: rgba(0, 0, 0, .7);}.reserve {    position: relative;    width: 90%;    height: 80%;    z-index: 999;    overflow: auto;    border-radius: 10px;    margin: 100px auto;    background-color: #fff;}

這樣寫確實沒問題,但是問題也跟著來了,滑動內容的時候body也會跟著滑動,下面是解決辦法。

給 html 和 body 都加上

.ban_body {    height: 100%;    overflow: hidden;}

我是這樣解決的 :當點擊按鈕的時候為 html 和 body 加上  .ban_body ,這樣body就不跟著一起滑動了。

    $(document).on("click",".btn", function () {        $("html,body").addClass("ban_body")        $(".mask").show(100);    })

關閉的時候別忘刪掉哦。

移動端body跟著模態框一起滑動問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.