简体   繁体   English

在隐藏div加载时保留空白区域

[英]Reserve white space while hidden div is loading

In the code below, a div is hidden until it gets OK from a 3rd-party server, and then it's rendered via jquery. 在下面的代码中,div被隐藏,直到它从第三方服务器获得OK,然后通过jquery呈现。 The purpose is to create an impression of smooth loading. 目的是给人一种平滑加载的印象。 The problem is that the paragraph below this div is pushed down after the div is loaded, which defeats the purpose of the trick. 问题是该div下方的段落在div加载后被下推,这违背了技巧的目的。 What's the best way to fix that? 解决这个问题的最佳方法是什么?

http://jsfiddle.net/Sh7aA/7/ http://jsfiddle.net/Sh7aA/7/

<div id="fb-root"></div>
<p style="text-align:center">Follow us!</p>
<center style="display: none;" id="social">
    <div class="g-plusone" data-size="medium"></div>
    <div class="fb-like" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
</center>

<p style="text-align:center">Test paragraph of text<br>
Paragarph continued</p>

设置加载内容的容器的min-height ,以匹配加载内容的高度。

Give the element a size, and set it's opacity to zero so the content is invisible 为元素指定大小,并将其不透明度设置为零,以使内容不可见

#social {opacity: 0; height: 25px; width: 100%; position: relative;}

Then animate in the content 然后在内容中制作动画

$('#social').animate({opacity : 1}, 1000);

FIDDLE 小提琴

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

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