我试图淡出section#secondary
的内容,一旦内容淡出,父级(section#secondary
)应该在滑块动画中为“关闭”设置动画。如何从.fadeOut效果回调中使用.animate的持续时间设置?
所有这些工作,但持续时间不是,我不明白为什么。
这里是我的代码:
HTML
<section id="secondary">
<a href="#" class="slide_button">«</a> <!-- slide in/back button -->
<article>
<h1>photos</h1>
<div class="album_nav"><a href="#">photo 1 of 6</a> | <a href="#">create an album</a></div>
<div class="bar">
<p class="section_title">current image title</p>
</div>
<section class="image">
<div class="links">
<a class="_back album_link" href="#">« from the album: james new toy</a>
<nav>
<a href="#" class="_back small_button">back</a>
<a href="#" class="_next small_button">next</a>
</nav>
</div>
<img src="http://localhost/~jannis/3781_doggie_wonderland/www/preview/static/images/sample-image-enlarged.jpg" width="418" height="280" alt="" />
</section>
</article>
<footer>
<embed src="http://localhost/~jannis/3781_doggie_wonderland/www/preview/static/flash/secondary-footer.swf" wmode="transparent" width="495" height="115" type="application/x-shockwave-flash" />
</footer>
</section> <!-- close secondary -->
jQuery的
// =============================
// = Close button (slide away) =
// =============================
$('a.slide_button').click(function() {
$(this).closest('section#secondary').children('*').fadeOut('slow', function() {
$('section#secondary').animate({'width':'0'}, 3000);
});
});
由于section#secondary
的内容是可变的,我用的是*
选择。
会发生什么事是,fadeOut
使用适当slow
速度,但一旦回调火灾(一旦内容淡出)的section#secondary
动画播放至width: 0
几毫秒之内,而不是3000毫秒(3秒)我将动画持续时间设置为。
任何想法,将不胜感激。
PS:我不能在此处发布示例,但由于这更多是jQuery理论的问题,所以我不认为这里需要示例。 纠正我,如果我错了..
每一级子触发一次,因此3次这不是我仅与该代码看到的行为:http://jsfiddle.net/ eKeQ2 /外部/附加内容必须在您的实际页面上进行。应该检查'$('section#secondary:not(:animated)')',因为你正在为每个褪色的孩子开始动画而不是一次。 – 2010-05-11 10:32:46
我更新了我的答案。我猜这是因为你没有为'#secondary'设置任何大小的属性,所以当它的内容被删除时,它会自动崩溃。我的新答案(如下)在点击时静态设置其大小,并在动画之前。 – user113716 2010-05-11 11:41:54