单击时避免菜单切换关闭

时间:2018-11-29 11:00:46

标签: 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>

1 个答案:

答案 0 :(得分:0)

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

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

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

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

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