滚动 - 当模态打开时禁用部分滚动

时间:2017-03-02 19:38:39

标签: jquery css jquery-scrollify

我在我的网站上使用https://projects.lukehaas.me/scrollify/,在打开模式后我无法禁用它的滚动功能。我使用标准的onclick动作来打开模态,所以我可以在那里注入一些东西,但我不确定是什么。

这是我的Scrollify初始化:

jQuery.scrollify({
section : ".vc_section",
sectionName : "section-name",
interstitialSection : "",
easing: "easeOutExpo",
scrollSpeed: 2000,
offset : 0,
scrollbars: true,
standardScrollElements: "footer",
setHeights: true,
overflowScroll: true,
updateHash: false,
touchScroll: true,
before:function(i,panels) {
var ref = panels[i].attr("data-section-name");
if(ref === "first") {
   jQuery("#hero-container").removeClass("hidden");
}

if(ref === "second") {
jQuery("#hero-container").addClass("hidden");
}
},
after:function() {},
afterResize:function() {},
afterRender:function() {}
});

然后我通过一个简单的onclick函数调用一个模态:

    jQuery('.schedule-visit-toggle, .schedule-visit-toggle a').on('click touchstart', function(evt) {
    evt.stopPropagation();
    evt.preventDefault();

    jQuery('#schedule-visit-modal').foundation('open');
});

3 个答案:

答案 0 :(得分:3)

打开模态时,调用$.scrollify.disable()禁用Scrollify。

答案 1 :(得分:0)

无论如何我会试着试一试......

我想当模态没有显示时,它的css中有display: none;

所以你能做的是:

if ($('#yourModalID').css('display') === 'none') {
  scrollify
} else {
    do not scrollify
});

可能它不起作用,但值得一试......

答案 2 :(得分:0)

我将此代码添加到 afterRender:function() {}

$(".mobile-menu-toggle").on("click",function() {
      $("body").toggleClass("layout-open");
       if($("body").hasClass('layout-open')){
          $.scrollify.disable();
       }else{
           $.scrollify.enable();
        }
});

并添加样式 css

 .layout-open{
    touch-action: none;
}

完美运行

相关问题