1、彈出層內(nèi)無(wú)需滑動(dòng)效果
//box:彈出層背景元素
box.addEventListener('touchmove', function(e){
e.preventDefault()
})
2、背景禁止滑動(dòng),彈出層內(nèi)可以滑動(dòng)
js部分
//點(diǎn)擊出現(xiàn)彈出層
$('.child').on('click',function(){
var top=$(window).scrollTop();
$('html').css({'overflow':'hidden','position':'fixed','top': -top+'px'})
})
//關(guān)閉彈出層時(shí)
$('.close').on('click', function() {
$('html').css({'overflow': 'auto','position': 'static'});
$('html,body').scrollTop(top);
})
進(jìn)一步若想要使滑動(dòng)更加順暢,在滾動(dòng)時(shí)模擬原生的彈性滾動(dòng)效果
可以在滾動(dòng)元素時(shí)加一句css
-webkit-overflow-scrolling : touch;
overflow-y:auto;