javascript - 单击时避免菜单切换关闭
问题描述
我.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();
}
});
推荐阅读
- python - 'int' 对象不可调用:查找列表元素的总和
- c++ - (C++)试图将双精度转换为整数(解释)
- node.js - 如何正确管道 Node.js 双工流?
- php - PHP - 使用临时 URL 从目录访问上传的文件
- php - Codeigniter 控制器编号到字转换器
- python-3.x - 如何通过串行代码将python-to-arduino转换为通过串行代码的python3-to-arduino?
- c - 为什么这个键盘输入在 C 中不作为 Char
- spring-boot - Spring Boot:始终获取 404 状态
- python - PyQT 中的多个页面的标准是什么?
- c - 将双精度数转换为字符串时,第一个字符串字符可以是什么?