jquery覆盖加载条div

Mat*_*hew 18 css jquery overlay

所以我有一个数据表,我正在使用ajax获取数据.检索数据时,表格中的数据消失,出现一个小的加载圆圈.我更喜欢保留数据(我知道该怎么做)以及加载圆圈出现在它的中心的桌子上(不一定是垂直的,至少是水平的),还有一个稍微透明的背景阻挡表格的视图有点(不是网页的其余部分).如何在桌面上显示div并执行此操作?

gbl*_*zex 72

[ 看到它在行动 ]

HTML

<div id="overlay">
  <img src="http://www.sanbaldo.com/wordpress/wp-content/bigrotation2.gif" 
    id="img-load" />
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

#overlay { 
  display:none; 
  position:absolute; 
  background:#fff; 
}
#img-load { 
  position:absolute; 
}
Run Code Online (Sandbox Code Playgroud)

使用Javascript

$t = $("#table"); // CHANGE it to the table's id you have

$("#overlay").css({
  opacity : 0.5,
  top     : $t.offset().top,
  width   : $t.outerWidth(),
  height  : $t.outerHeight()
});

$("#img-load").css({
  top  : ($t.height() / 2),
  left : ($t.width() / 2)
});
Run Code Online (Sandbox Code Playgroud)

然后,当你装载东西时,你只需说:

$("#overlay").fadeIn();
Run Code Online (Sandbox Code Playgroud)

当你完成时:

$("#overlay").fadeOut();
Run Code Online (Sandbox Code Playgroud)

注意:加载图像根据要求显示为垂直和水平居中.此外,只有表格才会覆盖整个页面而不是请求.


jor*_*ens 11

只需使用jQuery的.html()方法将带有加载圆的新div注入到持有表的div中.然后使用CSS来设置它的样式.也许给它一个不透明的背景图像.并相对或绝对地定位加载圆.

说你有:

<div id="table_container>
    <table>
        <tr>
            <td>something</td>
            <td>something</td>
        </tr>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

加载新数据时使用:

$('div#table_container').html('<div id="overlay"><img src="path/to/loading/img.png" class="loading_circle" alt="loading" /></div>');
Run Code Online (Sandbox Code Playgroud)

并设计风格如下:

#overlay {
    width: 100%;
    background: url('path/to/opaque/img.png') repeat;
    position: relative;
}

#overlay img.loading_circle {
    position: absolute;
    top: 50%;  // edit these values to give you
    left: 50%; // the positioning you're looking for.
}
Run Code Online (Sandbox Code Playgroud)