为什么不做这样的事情?只需将其更改为 AJAX 并success
用作您的触发器。基本上是一个永无止境的动画 gif,等待您的数据加载。
<div id="chartDiv"></div>
var chartDiv = document.getElementById("chartDiv");
var loadingImg = document.createElement("img");
var newImg = document.createElement("img");
loadingImg.src = "http://i1267.photobucket.com/albums/jj559/rizkytanjo96/loading.gif";
chartDiv.appendChild(loadingImg);
function placeLoaded() {
chartDiv.removeChild(loadingImg);
chartDiv.appendChild(newImg);
}
function getNew() {
newImg.addEventListener("load", placeLoaded, false);
newImg.src = "http://i1276.photobucket.com/albums/y462/staffpicks/Animated_GIFs/ahhhh.gif";
}
setTimeout(getNew, 10000);
在jsfiddle上
或者,如果您不想要动画 gif,您可以使用 javascript 执行类似的操作。
#pwidget {
background-color:lightgray;
width:254px;
padding:2px;
-moz-border-radius:3px;
border-radius:3px;
text-align:left;
border:1px solid gray;
}
#progressbar {
width:250px;
padding:1px;
background-color:white;
border:1px solid black;
height:28px;
}
#indicator {
width:0px;
background-image:url("http://img827.imageshack.us/img827/269/shadedgreen.png");
height:28px;
margin:0;
}
#loading {
text-align:center;
width:250px;
}
var pwidget = {
maxprogress: 250,
actualprogress: 0,
itv: 0,
delay: 10,
prog: function () {
if (pwidget.actualprogress >= pwidget.maxprogress) {
clearInterval(pwidget.itv);
return;
}
var indicator = document.getElementById("indicator");
pwidget.actualprogress += 1;
indicator.style.width = pwidget.actualprogress + "px";
if (pwidget.actualprogress === pwidget.maxprogress) {
pwidget.restart();
}
},
start: function () {
pwidget.itv = setInterval(pwidget.prog, pwidget.delay);
},
stop: function () {
clearInterval(pwidget.itv);
},
restart: function () {
pwidget.actualprogress = 0;
pwidget.stop();
pwidget.start();
},
element: function () {
var pwidget = document.createElement("div"),
progressbar = document.createElement("div"),
indicator = document.createElement("div"),
loading = document.createElement("div");
pwidget.id = "pwidget";
progressbar.id = "progressbar";
indicator.id = "indicator";
loading.id = "loading";
loading.textContent = "Loading ...";
progressbar.appendChild(indicator);
pwidget.appendChild(progressbar);
pwidget.appendChild(loading);
return pwidget;
}
};
var chartDiv = document.getElementById("chartDiv");
var widget = pwidget.element();
var newImg = document.createElement("img");
function placeLoaded() {
pwidget.stop();
chartDiv.removeChild(widget);
chartDiv.appendChild(newImg);
}
function getNew() {
newImg.addEventListener("load", placeLoaded, false);
newImg.src = "http://i1276.photobucket.com/albums/y462/staffpicks/Animated_GIFs/ahhhh.gif";
}
chartDiv.appendChild(widget);
pwidget.start();
setTimeout(getNew, 10000);
在jsfiddle上
或者jQueryUI 有一个进度条,你可以对我上面的例子做类似的事情。