【问题标题】:Block scroll on Modal open模态打开时阻止滚动
【发布时间】:2016-11-10 21:26:40
【问题描述】:

我正在开发这个website,(使用Fullpage.js 插件构建)。在第一部分中,我有一个模式窗口(通过单击 orange + 符号)。

如您所见,如果在 Modal 打开时用鼠标滚动,您可以滚动到下一页。

我怎样才能阻止这个? 我只需要在您关闭 Modal 时使其可滚动。

PS:如果有帮助的话,我正在使用 Wordpress...

编辑:我试过这个

JS

<script type="text/javascript"> 
$(document).on('click', '.ts-awesome-plus', function() {
$.fn.fullpage.setAllowScrolling(false);
$.fn.fullpage.setKeyboardScrolling(false);
}); 
</script>

【问题讨论】:

  • 你用javascript应用滚动?有什么功能? Modal打开时不能应用滚动功能!

标签: fullpage.js


【解决方案1】:

当模态框打开时,您需要禁用$.fn.fullpage.setAllowScrolling(false) 的滚动以及键盘滚动$.fn.fullpage.setAllowScrolling(false)。在模态关闭时启用它们。这是一个工作示例,点击Modal OpenModal Close

$('#fullpage').fullpage({
  anchors: ['page1', 'page2', 'page3', 'page4'],
  sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
});

//adding the actions to the buttons
$(document).on('click', '#turnOff', function() {
  $.fn.fullpage.setAllowScrolling(false);
  $.fn.fullpage.setKeyboardScrolling(false);
});

$(document).on('click', '#turnOn', function() {
  $.fn.fullpage.setAllowScrolling(true);
  $.fn.fullpage.setKeyboardScrolling(true);
});
.section {
  text-align: center;
  font-size: 3em;
}
/**
Fixed button outside the fullpage.js wrapper
*/

#turnOff,
#turnOn {
  position: fixed;
  z-index: 999;
  font-size: 2em;
  cursor: pointer;
  top: 20px;
}
#turnOff {
  left: 20px;
}
#turnOn {
  left: 240px;
}
<link href="https://rawgit.com/alvarotrigo/fullPage.js/master/jquery.fullPage.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/alvarotrigo/fullPage.js/master/jquery.fullPage.js"></script>

<button id="turnOff">Modal Open</button>
<button id="turnOn">Modal Close</button>


<div id="fullpage">
  <div class="section">One</div>
  <div class="section">Two</div>
  <div class="section">Three</div>
  <div class="section">Four</div>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 1970-01-01
    • 2019-07-26
    • 2019-08-09
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    相关资源
    最近更新 更多