在開(kāi)發(fā)中,彈窗是非常常見(jiàn)的功能,但是寫(xiě)完彈窗下面的蒙層還可以滑動(dòng),就非常的不爽,所以有了這個(gè)文章
環(huán)境是vue開(kāi)發(fā),所以開(kāi)始說(shuō)方法
1、方法一:
各種方法,同樣也會(huì)把你彈窗中的內(nèi)容變成不可滾動(dòng)的,所以彈窗內(nèi)容不需要滾動(dòng)時(shí),可以用這個(gè)方法
<div class="dailog" v-if="isShow" @touchmove.prevent>注意:一定是在你的彈窗中去寫(xiě)</div>
2、方法二:
/**
* 阻止?jié)L動(dòng)條滾動(dòng)
*/
const stopScroll = () => {
document.body.style.top = '0'
document.body.style.position = 'fixed'
document.body.style.height = '100%'
document.body.style.overflow = 'hidden'
}
/**
* 恢復(fù)滾動(dòng)條滾動(dòng)
*/
const autoScroll = () => {
document.body.style.position = 'initial'
document.body.style.overflowY = 'auto'
}
在彈窗顯示時(shí),阻止?jié)L動(dòng);彈窗關(guān)閉時(shí),滾動(dòng)正常。這種情況,彈窗中的內(nèi)容可以正常滾動(dòng),然后其它的部分不可滾動(dòng)
調(diào)用:
getdrawList () {
this.isDrawList = true
this.isShow = true
utils.stopScroll()
},
handleCancel () {
this.isShow = false
utils.autoScroll()
},