2016-02-26 76 views
0

我有這樣的代碼,它的工作原理產品:停用和激活身體滾動在手機瀏覽器

$(".menu").on("click",function(event) {  
    $(".navigation").css("opacity", "1");  
    $('body').on('touchmove', function (e) { 
     if (!$('.info').has($(e.target)).length) e.preventDefault(); 
    }); 
}); 

所以我想要做的是讓滾動回來一次我隱藏的div不透明。我正在嘗試使用這段代碼,但我無法得到它。

$(".menu-i-cerrar").on('click', function() { 
    $(".navigation").css("opacity", "0"); 
    $('body').on('touchmove', function (e) { 
     return true; 
    });                               
}); 

任何想法?

回答

0

您可以將邏輯存儲在函數中,然後將其關閉和打開。

var disableScrollDueToSomething = function (e) { 
    if (!$('.info').has($(e.target)).length) e.preventDefault(); 
}; 

$('body').on('touchmove', disableScrollDueToSomething); 

//later to remove it 
$('body').off('touchmove', disableScrollDueToSomething); 
+0

謝謝!它就像一個魅力... :-) – Antistar