简体   繁体   English

jQuery内容过滤器褪色效果

[英]Jquery content filter fading effect


I wrote a little jquery content filter: jsfiddle . 我写了一个小jQuery内容过滤器: jsfiddle

If I switch between "gfx" and "coding" for example I get this ugly height reseizing effect on the red parent div. 例如,如果我在“ gfx”和“编码”之间切换,则会在红色父级div上获得这种丑陋的高度重新定位效果。 My goal is fading the little divs out then in, at the same place. 我的目标是将小div移到同一位置,然后淡入。 Without any resizing and without using a fixed height. 没有任何大小调整,也没有使用固定的高度。 (Number of items can differ later) (项目数量稍后可能会有所不同)

Any hints how I can achieve this? 有什么提示可以实现这一目标吗?

var filter = $(this).attr('data-filter');
$('#filter_container .filteritem:not(' + filter + ')').fadeOut('slow', function () {
    $('#filter_container ' + filter + '').fadeIn('fast');
});

For details and working example see the jsfiddle. 有关详细信息和工作示例,请参见jsfiddle。

http://jsfiddle.net/k6BPs/8/ http://jsfiddle.net/k6BPs/8/

The fadeOut() callback is apparently called for each element. 显然,每个元素都将调用fadeOut()回调。 See here . 看这里 That way it will be triggered right away preventing a nice fadeIn() effect after the fadeOut(). 这样一来,它将立即触发,从而防止在fadeOut()之后产生很好的fadeIn()效果。

You can overcome this problem by using the .promise() and .done(function(){}) methods though. 您可以通过使用.promise().done(function(){})方法来克服此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM