Bootstrap表加载进度条覆盖

时间:2015-09-07 06:58:25

标签: html css twitter-bootstrap

我的HTML和分页中有一个表,用ajax加载下一页。 在加载数据时,我希望用Bootstrap进度条覆盖div。



function loadingTable(divID) {

	var html = " <div class='table-loading-overlay'>"
		+ " <div class='table-loading-inner'>"
		+ "<div class=\"col-xs-4 col-xs-offset-4\">"
		+ "<div class=\"progress\"> "
		+ "<div class=\"progress-bar progress-bar-striped progress-bar-streit active\" role=\"progressbar\" aria-valuenow=\"100\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 100%\">"
		+ "        <span class=\"sr-only\">Loading...</span>"
		+ "    </div>"
		+ "    </div>"
		+ " </div>"
		+ " </div>"
		+ " </div>";
	$('#' + divID).append(html);
}
function prevPage(){}
function nextPage(){}
&#13;
.table-loading-inner {
    width: 100%;
    height: 100%;
}
.table-loading-overlay {
    width: 100%;
    height: 100%;
    position: relative;
    display: block;
    z-index: 10;
    background:  #000000;
    z-index: 100;
    opacity: 0.5;
}
&#13;
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
 
  <div id="userList">
			<table class="table table-striped table-hover">
				<thead>
				<tr>
					<th>Name</th>
					<th>Status</th>
				</tr>
				</thead>
				<tbody>
					<tr>
                  <td>Test 1</td>
                  <td>active</td>
                  </tr>                      
					<tr>
                  <td>Test 2</td>
                  <td>active</td>
                  </tr>                      
					<tr>
                  <td>Test 3</td>
                  <td>active</td>
                  </tr>
					<tr>
                  <td>Test 4</td>
                  <td>active</td>
                  </tr>
					<tr>
                  <td>Test 5</td>
                  <td>active</td>
                  </tr> 
				</tbody>
			</table>
			<div>
				<span style="float:right;"> 10 Users <i class="fa fa-list"></i></span>
			</div>
			<div class="paginator">
				  <span class="btn btn-default" onclick="prevPage();loadingTable('userList');"> prev</span>
				  <span class="btn btn-default"  onclick="nextPage();loadingTable('userList');">next</span>
			</div>
		</div>		 
&#13;
&#13;
&#13;

如何让table-loading-overlay超过桌子? 由于表格可以在HTML中无处不在,我无法使用绝对位置...

1 个答案:

答案 0 :(得分:2)

如果您不想使用绝对定位的div,可以给父div一个固定的位置。哪个应该也可以。表格在文档中的位置无关紧要。

以下是具有固定定位父级的示例。

function loadingTable(divID) {

  var html = " <div class='table-loading-overlay'>"
  + " <div class='table-loading-inner'>"
  + "<div class=\"col-xs-4 col-xs-offset-4\">"
  + "<div class=\"progress\"> "
  + "<div class=\"progress-bar progress-bar-striped progress-bar-streit active\" role=\"progressbar\" aria-valuenow=\"100\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 100%\">"
  + "        <span class=\"sr-only\">Loading...</span>"
  + "    </div>"
  + "    </div>"
  + " </div>"
  + " </div>"
  + " </div>";

  $('#' + divID).append(html);
  $('.table-loading-overlay').css('height', $('#' + divID).height() + 'px');
  $('.table-loading-inner').css('padding-top', ($('#' + divID).height() / 2) + 'px');
}
function prevPage(){}
function nextPage(){}
.table-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background:  #000000;
  opacity: 0.5;
}

.table-loading-inner {
  width: 100%;
  height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>


<div id="userList">
  <table class="table table-striped table-hover">
    <thead>
      <tr>
        <th>Name</th>
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Test 1</td>
        <td>active</td>
      </tr>                      
      <tr>
        <td>Test 2</td>
        <td>active</td>
      </tr>                      
      <tr>
        <td>Test 3</td>
        <td>active</td>
      </tr>
      <tr>
        <td>Test 4</td>
        <td>active</td>
      </tr>
      <tr>
        <td>Test 5</td>
        <td>active</td>
      </tr> 
    </tbody>
  </table>
  <div>
    <span style="float:right;"> 10 Users <i class="fa fa-list"></i></span>
  </div>
  <div class="paginator">
    <span class="btn btn-default" onclick="prevPage();loadingTable('userList');"> prev</span>
    <span class="btn btn-default"  onclick="nextPage();loadingTable('userList');">next</span>
  </div>
</div>