如果這是你原來的代碼:
$('.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」到‘身體’和‘位置是:固定/相對’溢出-Y:隱藏/滾動」爲在這裏看到:
$('.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' 到 '空' 關閉對話框時。
那固定的跳轉問題上的手機和PC,但在移動現在它仍然是滾動而不是位置:固定在蓋上來。 –
您可以嘗試使用我添加到我的答案中的移動編輯。 –
我用你的方式更新了jquery,但當退出按鈕被點擊時,我需要撤消preventDefault()和stopPropagation()的幫助,這樣網站纔會恢復正常。 http://jsbin.com/saditujuli/edit?html,css,js,output –