美文网首页
h5页面弹窗实现区域滚动

h5页面弹窗实现区域滚动

作者: 万年孤寂_ | 来源:发表于2018-01-26 11:49 被阅读0次

#序言

项目中经常会遇到在一个弹窗内实现区域滚动(比如查看我的领取记录等),原本以为很好实现,确实也很好实现,但实现的时候再手机端除夕拿了各种各样的问题。所以总结一下方便后人,也欢迎大神指点!!!

1.简单介绍

废话不多说,就是一个简单的嵌入到app内的h5抽奖活动页面,在当前页面的弹窗内显示获奖列表,由于列表长度也许会很长,所以弹窗内只能用滚动实现(当然可以重新开一个页面)。废话补多少,直接上代码

2.html部分

<!--领取记录弹窗-->
<div class="promptwing" style="display: none;">
    <div class="promptbg">
        <div id="wrapper">
            <div id="scroller">
                <div class="content">
                    <div class="title">
                        <span>
                            中奖时间
                        </span>
                        <span>
                            奖品名称
                        </span>
                    </div>
                    <ul class="lists" id="lists">
                        <li>
                            <span>2017.3.11 10:10:10</span><span>头像特效(随机)</span>
                        </li>
                        <li>
                            <span>2017.3.11 10:10:10</span><span>跑车</span>
                        </li>
                        <li>
                            <span>2017.3.11 10:10:10</span><span>南瓜马车</span>
                        </li>
                        <li>
                            <span>2017.3.11 10:10:10</span><span>南瓜马车</span>
                        </li>
                        <li>
                            <span>2017.3.11 10:10:10</span><span>南瓜马车</span>
                        </li>
                        <li>
                            <span>2017.3.11 10:10:10</span><span>南瓜马车</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="activebtn activebtnls">
            <img src="img/activebtn.png" alt="">
        </div>
    </div>
</div>
<!--页面整体部分-->
<div class="boxes">
</div>

3.css部分(less)

body{
    background: #e11139;
    // 我的领奖记录弹窗
    .promptwing{
    position: fixed;
    width:100%;
    height:100%;
    z-index:9999;
    overflow: hidden;
    background-color: rgba(0,0,0,0.7);
    display: none;
    .promptbg{
      width:8.8rem;
      height:11.376rem;
      background: url("../images/promptlistbg.png") no-repeat;
      background-size: 100%;
      margin:0 auto;
      margin-top:1.5rem;
      position: relative;
      //iscroll滚动列表
      #wrapper{
        width: 7.904rem;
        position: absolute;
        top: 3.6rem;
        left: 50%!important;
//      transform:translate(-50%);
        margin-left: -3.952rem;
        bottom: 3rem;
        overflow-x: hidden;
        #scroller{
          width: 100%;
          box-sizing: border-box;
          z-index: 10;
          //padding-left: 0.384rem;
          //padding-right: 0.384rem;
          .content{
            width: 100%;
            margin: 0 auto;
            .title{
              width: 100%;
              font-size: 0;
              span{
                display: inline-block;
                width: 50%;
                line-height: 1rem;
                font-size: 0.48rem;
                text-align: center;
                color: #ffffff;
              }
            }
            .lists{
              width: 100%;
              font-size: 0;

              span{
                //display: inline-block;
                width: 50%;
                float: left;
                color: #ffffff;
                line-height: 1rem;
                font-size: 0.384rem;
              }
              span:nth-child(1){
                text-align: center;
                //line-height: 0.6rem;
              }
              span:nth-child(2){
                text-align: left;
                padding-left:0.8rem;
                box-sizing: border-box;
                //line-height:1.2rem;
              }
            }
          }
        }
      }

      .activebtn{
        position: absolute;
        left: 50%;
//      transform:translate(-50%);
        margin-left: -2.056rem;
        //top:9rem;
        width:4.112rem;
        height:1.024;
        img{
          width:100%;
        }
      }
      .activebtnls{
        top: 9.44rem;
      }
    }
  }

    
}

4.js部分

//弹窗消失操作
$('.activebtn').on('click',function () {
    $('.promptwing').hide();
    $("body,html").css({"overflow":"auto"});
    $('.boxes').css("position","static");
})

//查看我的领取记录
$('#listlog').on('click',function () {
    $("body,html").css({"overflow":"hidden"});
    $('.boxes').css("position","fixed");
    $('.promptwing').show();
    $("#wrapper").css({"overflow":"auto"});
  
})

总结

这样就可以实现弹窗里面区域滚动,但是整体不滚动的效果,也不会影响布局.我刚开始js是给body设置的fixed,但是整个页面的布局向做移动,最后给body下一级的父元素.boxes设置就是好的,没想明白为啥给body设置fixed不行,欢迎大神们的指导

相关文章

  • h5移动端相关问题记录

    禁止H5 ios滚动回弹,解决弹窗内滚动和页面同步滚动问题(页面为swiper整屏翻页) 引入inobounce....

  • h5页面弹窗实现区域滚动

    #序言 项目中经常会遇到在一个弹窗内实现区域滚动(比如查看我的领取记录等),原本以为很好实现,确实也很好实现,但实...

  • 2021-07-09 Vue 解决移动端滑动穿透问题

    当页面有弹窗时,并且这个弹窗有滚动事件时,这时候会遇到bug,最底部的内容区域会跟着滚动,导致弹窗滚动不生效,以下...

  • uniapp 解决弹窗滚动冲突

    问题 页面是可以滚动的长列表,弹窗也是列表可以滚动。 解决 弹窗时禁止弹窗下的页面滑动。弹窗时底层页面不超出一整屏...

  • 移动端 弹出层禁止弹窗下的页面滚动

    制作弹窗的时候遇到的问题:页面很长,需要滚动。弹窗里也需要滚动。当滚动弹窗内的内容时,发现弹窗的内容不滚动,反而是...

  • H5 移动端滚动穿透

    一般 H5 常见的活动页,如果当前页面超过一屏,同时在当前页面显示弹窗,整个页面依旧可以滚动 1.功能 常见的活动...

  • uniapp采坑日记之scroll-view

    scroll-view 可滚动视图区域。用于区域滚动。 需注意在webview渲染的页面中,区域滚动的性能不及页面...

  • H5打开第三方地图APP

    实现思路: H5页面弹出弹窗选择 选择后跳转对应地图的H5页 让地图的H5页唤起各自的APP

  • 小程序弹窗阻止滑动的两种方法

    弹出 fixed 弹窗后,在弹窗上滑动会导致下层的页面一起跟着滚动。 场景1:弹窗内无滚动内容 可以在弹窗最外层元...

  • 小程序集合

    目录 问题集合页面弹出背景滚动表单绑定bindsubmit无效 问题集合 页面弹出背景滚动 在页面中弹窗弹出,对弹...

网友评论

      本文标题:h5页面弹窗实现区域滚动

      本文链接:https://www.haomeiwen.com/subject/ozuiaxtx.html