如何淡出显示: 行内块

在我的页面中,我有一大堆(大约30个)空间节点,应该添加不可见的,并淡入时,他们完全加载。
元素需要一个 display: inline-block 样式。

我想使用 jquery。FadeIn ()函数。这要求元素最初有一个 display: none; rule 来隐藏它。 在 fadeIn ()之后,偏离过程的元素有默认的显示: 继承;

除了继承之外,如何使用带有显示值的淡出功能?

77038 次浏览

You could use jQuery's animate function to change the opacity yourself, leaving the display unaffected.

Just to flesh out Phil's good idea, here is a fadeIn() that loads fades in each element with the class .faded in turn, converted to animate() :

Old:

$(".faded").each(function(i) {
$(this).delay(i * 300).fadeIn();
});

New:

$(".faded").each(function(i) {
$(this).delay(i * 300).css('opacity',0).animate({'opacity': 1}, 500);
});

Hope that help another jQuery newb like myself :) If there's a better way to do that, please tell us!

$("div").fadeIn().css("display","inline-block");

According to the jQuery docs for .show(),

If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline.

So my solution to this problem was to apply a css rule to a class display: inline-block on the element, then I added another class called "hide" which applies display: none; When I .show() on the element, it showed inline.

Makura's answer did not work for me so my solution was

<div id="div" style="display: none">Some content</div>


$('#div').css('display', 'inline-block').hide().fadeIn();

hide immediately applies display: none but before that it saves the current display value in the jQuery data cache which will be restored by the subsequent animation calls.

So the div starts statically defined as display: none. Then it is set to inline-block and immediately hidden just to be faded in back to inline-block

This works even with display:none preset by css. Use

$('#element').fadeIn().addClass('displaytype');

(and also $('#element').fadeOut().removeClass('displaytype');)

with setup in CSS:

#element.displaytype{display:inline-block;}

I consider this a workaround as I believe fadeIn() should work so that it would just remove the last rule - display:none when set to #element{display:inline-block;display:none;} but it is malfunctioningly removing both.