2016-08-26 38 views
0

我的项目只是水平滚动。这意味着X.如何启用和禁用页面滚动

#landscape是整个容器。

起初,我禁用了滚动#landscape

之后,当我在点击.close-reveal-modal一个div褪色。

在这种div我仍然不能滚动$('#landscape')。 之后,我想在关闭此.close-reveal-modal后启用$('#landscape')的滚动。

我累了把$('#landscape').off这意味着启用它。但它不适合我。

$('#landscape').on('scroll touchmove mousewheel', function(e){ // on off means enable and disable 
    e.preventDefault(); 
    e.stopPropagation(); 
    return false; 
}) 

$('.close-reveal-modal').click(function(){ 
    setTimeout(function(){ 
     $('#second_load').fadeIn(300); 
    }, 1000); 
}); 

$('#second_load').click(function(){ 
    $('#second_load').fadeOut(300); 

    $('#landscape').off('scroll touchmove mousewheel', function(e){ // on off means enable and disable 
     e.preventDefault(); 
     e.stopPropagation(); 
     return false; 
    }) 
}); 

回答

0
function freeze() { 
     var top = $("html").scrollTop() ? $("html").scrollTop() : $("body").scrollTop(); 
     var left = $("html").scrollLeft() ? $("html").scrollLeft() : $("body").scrollLeft(); 
     if(window.innerWidth > document.documentElement.clientWidth) { 
      $("html").css("overflow-y", "scroll"); 
     } 
     if(window.innerHeight > document.documentElement.clientHeight) { 
      $("html").css("overflow-x", "scroll"); 
     } 
     $("html").css({"width": "100%", "height": "100%", "position": "fixed", "top": -top, "left": -left}); 
} 
function unfreeze() { 
     $("html").css("position", "static"); 
     $("html, body").scrollTop(-parseInt($("html").css("top"))); 
     $("html, body").scrollLeft(-parseInt($("html").css("left"))); 
     $("html").css({"position": "", "width": "", "height": "", "top": "", "left": "", "overflow-y": "", "overflow-x": ""}); 
} 

来源:https://github.com/HubSpot/vex/issues/155

+0

我想你的代码。我不确定我是否正确应用。但它对我不起作用。 –

相关问题