gpt4 book ai didi

单击触发器并关闭同一按钮时,JQuery 动画并打开 div

转载 作者:行者123 更新时间:2023-12-01 08:41:17 24 4
gpt4 key购买 nike

我有一段 HTML,我希望在单击时为 div 制作动画,并在再次单击时关闭。 HTML:

<a href="#" class="menu_greyed performance_menu_trigger">My Details <span class="push_right">&#x25BC;</span></a>
<div class="performance_menu_holder">
<a href="details" class="push_right performance_menu_item">Details</a>
</div>

JQuery:

$(document).ready(function(){
$('.performance_menu_holder').hide()
$('.performance_menu_trigger').click(function(){
$('.performance_menu_holder').animate({ "opacity" : "show", bottom: "100" }, 500);
$('.performance_menu_trigger').addClass('performance_menu_trigger_close');
});
$('.performance_menu_trigger_close').click(function(){
$('.performance_menu_holder').animate({ "opacity" : "show", top: "100" }, 500);
$('.performance_menu_trigger').removeClass('performance_menu_trigger_close');
});
});

当您第一次单击它时,它会按应有的方式打开,但在打开时却不会。它不会关闭 div。

最佳答案

$(document).ready(function(){
$('.performance_menu_holder').hide()
$('.performance_menu_trigger').click(function(){
$('.performance_menu_holder').slideToggle({ "opacity" : "show", bottom: "100" }, 500);
$('.performance_menu_trigger').addClass('performance_menu_trigger_close');
});
$('.performance_menu_trigger_close').click(function(){
$('.performance_menu_holder').slideToggle({ "opacity" : "show", top: "100" }, 500);
$('.performance_menu_trigger').removeClass('performance_menu_trigger_close');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<a href="#" class="menu_greyed performance_menu_trigger">My Details <span class="push_right">&#x25BC;</span></a>
<div class="performance_menu_holder">
<a href="details" class="push_right performance_menu_item">Details</a>
</div>

您可以使用slideToggle代替动画。

$(document).ready(function(){
$('.performance_menu_holder').hide()
$('.performance_menu_trigger').click(function(){
$('.performance_menu_holder').slideToggle({ "opacity" : "show",
bottom: "100" }, 500);

$('.performance_menu_trigger').addClass('performance_menu_trigger_close');
});
$('.performance_menu_trigger_close').click(function(){
$('.performance_menu_holder').slideToggle({ "opacity" : "show", top: "100" }, 500);
$('.performance_menu_trigger').removeClass('performance_menu_trigger_close');
});
});

关于单击触发器并关闭同一按钮时,JQuery 动画并打开 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46993349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com