我想要显示/隐藏订单表单的动画效果很好,除了一个问题,表单在滑动时不会隐藏,它的一部分仍然可见。
HTML:
<div class="post">
<div class="post-content">
<a href="" class="order"></a>
...
</div>
<div class="order-form">
<a href="" class="close"></a>
...
</div>
</div>
jQuery:
$(".post .order").click(function () {
$(this).fadeOut();
$(this).parents('.post-content').slideUp();
$(this).parents('.post-content').next('.order-form').show();
$(this).parents().find('.close').fadeIn();
return false;
});
$(".order-form .close").click(function () {
$(this).fadeOut();
$(this).parents('.order-form').slideDown();
$(this).parents('.order-form').prev('.post-content').slideDown(function(){
$(this).parents('.order-form').prev('.post-content').css('display', 'none');
});
$(this).parents().find('.order').fadeIn();
return false;
});
。。正如你所看到的,我尝试过.hide()
,但它没有像预期的那样工作,它禁用了一个整洁的抽屉所需的向下滑动的动画(对吗?)喜欢效果。
谢谢!
发布于 2012-09-10 04:22:36
我尝试像这样的http://jsfiddle.net/2yrj6/2/
但我不知道这是不是你想要的
发布于 2012-09-10 04:23:11
我看到您正在回调函数中调用$(this).parents('.order-form').prev('.post-content').css('display', 'none');
。除了,$(this)
不再是close按钮。它就是刚刚被隐藏的元素。尝试在单击回调的第一行中声明var $this
。然后使用$this
而不是$(this)
。
其他注意事项:为了获得更好的性能,您应该使用parents('.post')
而不是parents()
。您可以使用.hide()
而不是.css('display', 'none')
。
https://stackoverflow.com/questions/12342482
复制相似问题