gpt4 book ai didi

javascript - SlideUp() 运行两次

转载 作者:行者123 更新时间:2023-12-03 12:43:15 27 4
gpt4 key购买 nike

我正在使用 jQuery 创建一个多选项卡 Accordion 。 “Headline 1”面板工作正常,但在“Headline 2”面板上运行 SlideDown() 方法两次。我注意到的另一个小问题是,当我单击按钮/链接和面板向下滑动之间存在一些延迟。

你可以看一下这里的jsfiddle来测试一下,看看问题所在:

http://jsfiddle.net/3VzTj/1/

jQuery:

$(document).ready(function() {
var class_link, class_div, content_div;
var all_panels = $('article > div.row').not(':first-child');

$(all_panels).hide();

$('div.buttons a').click(function() {
class_link = $(this).attr('class');
class_div = class_link.match(/[^-]+$/);
content_div = $(this).closest('article').find('div.' + class_div).parent();

if ($(content_div).is(':visible')) {
$(all_panels).slideUp();
} else {
$(all_panels).slideUp(function() {
$(content_div).hide().slideDown();
});
}

return false;
});
});

HTML:

<section class="grid-container">
<article>
<div class="row clearfix">
<div class="column half">
<h2>Headline 1</h2>
</div>
<div class="column opposite half buttons">
<a class="button-content1" href="#">Content 1</a>
<a class="button-content2" href="#">Content 2</a>
</div>
</div>

<div class="row clearfix">
<div class="column full content1">
<h1>Content 1</h1>
</div>
</div>

<div class="row clearfix">
<div class="column full content2">
<h1>Content 2</h1>
</div>
</div>
</article>


<article>
<div class="row clearfix">
<div class="column half">
<h2>Headline 2</h2>
</div>
<div class="column opposite half buttons">
<a class="button-content1" href="#">Content 1</a>
<a class="button-content2" href="#">Content 2</a>
</div>
</div>

<div class="row clearfix">
<div class="column full content1">
<h1>Content 1</h1>
</div>
</div>

<div class="row clearfix">
<div class="column full content2">
<h1>Content 2</h1>
</div>
</div>
</article>
</section>

最佳答案

// replace
$(all_panels).slideUp(function() {
$(content_div).hide().slideDown();
});

//with
$(all_panels).slideUp().promise().done(function() {
$(content_div).hide().slideDown();
});

关于javascript - SlideUp() 运行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23452268/

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