如果这是您的原始代码:
$('.responsive_click').on('click',function(){
$('.cover').fadeIn('slow');
$('.container').css('position','fixed');
});
$('.close-sign').on('click',function(){
$('.cover').fadeOut('slow');
$('.container').css('position','relative');
});
我将 '.container' 更改为 'body' 并将 'position: fixed/relative' 更改为 overflow-y: hidden/scroll',如下所示:
$('.responsive_click').on('click',function(){
$('.cover').fadeIn('slow');
$('body').css('overflow-y','hidden');
});
$('.close-sign').on('click',function(){
$('.cover').fadeOut('slow');
$('body').css('overflow-y','scroll');
});
这会阻止背景跳回顶部和背景滚动,同时蓝色标记叠加层向下。
编辑:对于移动设备,尝试window.ontouchmove = preventDefault;
像这样添加:
$('.responsive_click').on('click',function(){
$('.cover').fadeIn('slow');
$('body').css('overflow-y','hidden');
window.ontouchmove = preventDefault;
});
并在关闭对话框时将“preventDefault”更改为“null”。