javascript - 单击时避免菜单切换关闭

标签 javascript html css toggle

我在我的网站上使用了 .fadeToggle 菜单。

我有一些按钮在点击它们时显示不同的 div。

一切都是正确的,你可以在上面导航,但我想避免用户点击同一个按钮并关闭信息(这会使屏幕完全空白)。

如果我正在使用 e.stopPropagation(),我将无法通过它导航。

提前致谢。

HTML:

 </div><div id="toggleContainer2">
    <p><p>This is not an advertising platform, all selected agencies are more or less a subjective choice. The author reserves the right not to be responsible for the topicality, correctness, completeness or quality of the information provided. Liability claims regarding damage caused by the use of any information provided, including any kind of information which is incomplete or incorrect, will therefore be rejected. </p>
<p>All offers are not-binding and without obligation. Parts of the pages or the complete publication including all offers and information might be extended, changed or partly or completely deleted by the author without separate announcement.</p></p>
  </div>

...

 <a class="btn" id="trigger2">Disclaimer</a>

JS:

 <script>
$(document).ready(function() {
  // toggle advanced search
  $("#toggleContainer2").hide();
  $("#trigger2").click(function() {
    $("#toggleContainer2").fadeToggle(1500);
    $("#toggleContainer").hide();
  });
});

</script>

最佳答案

编辑:我已经重新阅读了您的帖子,您的问题是您不了解 .fadeToggle 的工作原理,因为您所描述的正是它的目的。

您需要阅读的是:fadeIn因为这是您需要的功能。

旧答案 您需要做的是改变您跟踪事件目标的方式。

假设你的下拉列表是 .dd 类,你的按钮类是 .menu_b,你会得到这样的东西

$('body').on('click','.menu_b',function(e){
  if($(e.target).hasClass('menu_b')) {
    $('.dd').fadeToggle();
  }
});

关于javascript - 单击时避免菜单切换关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53537503/

相关文章:

html - 如何修复粘性页脚? Flex 或 Grid 不工作

css - 我如何在我的 Bootstrap 模板中使用 gotham 圆 Angular 字体?

javascript - 如何将 printThis 插件功能分配给按钮?

javascript - HTML 选择框有关显示/隐藏 div 的 JQuery 问题

javascript - HTML 和 CSS 中的图标作为代码(例如 : &#xe348;)

php - 30秒超时解决方案不起作用

html - wordpress 中的麻烦样式按钮

javascript - 切换折叠菜单始终打开

javascript - 带有用户生成内容的菜单选项

javascript - 创建一个启动 iOS 应用程序或重定向到应用程序商店的链接