首页 > 解决方案 > 单击时避免菜单切换关闭

问题描述

.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>

标签: javascripthtmlcsstoggle

解决方案


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

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

较早的答案 您需要更改跟踪事件目标的方式。

假设您的下拉菜单为 .dd 类,而您的按钮类为 .menu_b,您将得到类似的内容

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

推荐阅读