jquery fade element does not show elements styled

2020-01-26 04:01发布

I have a bunch of thumbnails which I am loading with a style of visibility: hidden; so that they all maintain their correct layouts. Once the page is fully loaded I have a jquery function that fades them in. This worked when their style was set to display: none; but obviously the layout screwed up then. Any suggestions?

Heres the fade line:

$('.littleme').fadeIn('slow');

5条回答
虎瘦雄心在
2楼-- · 2020-01-26 04:04

Cant you use fadeTo(duration, value) instead? Surely this way you can fade to 0 and 1, that way you are not affecting the document flow...

查看更多
Ridiculous、
3楼-- · 2020-01-26 04:04

Try matching for the hidden element?

$(".littleme:hidden").fadeIn();

查看更多
淡お忘
4楼-- · 2020-01-26 04:13

try using opacity and animate():

$('.littleme').css('opacity',0).animate({opacity:1}, 1000);
查看更多
一纸荒年 Trace。
5楼-- · 2020-01-26 04:17

Add a few calls to the chain like this:

 $('.littleme').css('visibility','visible').hide().fadeIn('slow');

This will change it to display:none for 1 frame before fading in, occupying the area again.

查看更多
够拽才男人
6楼-- · 2020-01-26 04:27

<span style="opacity:0;">I'm Hidden</span>

To Show : $('span').fadeTo(1000,1)

To Hide  : $('span').fadeTo(1000,0)

The space is preserved in the DOM layout

http://jsfiddle.net/VZwq6/

查看更多
登录 后发表回答