美文网首页
vue写弹窗,阻止蒙层滑动,内容正常滑动

vue写弹窗,阻止蒙层滑动,内容正常滑动

作者: 努力study代码的小哪吒 | 来源:发表于2020-07-21 19:11 被阅读0次

    在开发中,弹窗是非常常见的功能,但是写完弹窗下面的蒙层还可以滑动,就非常的不爽,所以有了这个文章
    环境是vue开发,所以开始说方法
    1、方法一:

    各种方法,同样也会把你弹窗中的内容变成不可滚动的,所以弹窗内容不需要滚动时,可以用这个方法
    <div class="dailog" v-if="isShow" @touchmove.prevent>注意:一定是在你的弹窗中去写</div>
    

    2、方法二:

    /**
     * 阻止滚动条滚动
     */
    const stopScroll = () => {
      document.body.style.top = '0'
      document.body.style.position = 'fixed'
      document.body.style.height = '100%'
      document.body.style.overflow = 'hidden'
    }
    /**
     * 恢复滚动条滚动
     */
    const autoScroll = () => {
      document.body.style.position = 'initial'
      document.body.style.overflowY = 'auto'
    }
    在弹窗显示时,阻止滚动;弹窗关闭时,滚动正常。这种情况,弹窗中的内容可以正常滚动,然后其它的部分不可滚动
    调用:
       getdrawList () {
          this.isDrawList = true
          this.isShow = true
          utils.stopScroll()
        },
        handleCancel () {
          this.isShow = false
          utils.autoScroll()
        },
    

    相关文章

      网友评论

          本文标题:vue写弹窗,阻止蒙层滑动,内容正常滑动

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