===========copy this for you use,eg:after submit=======================
var divProgressDialogObj = document.createElement("div");
with(divProgressDialogObj)
{
id="divProgressDialog";
style.cssText = "BORDER: buttonhighlight 2px outset; FONT-SIZE: 8pt; Z-INDEX: 4; FONT-FAMILY: Tahoma; POSITION: absolute; BACKGROUND-COLOR: buttonface; DISPLAY:none; WIDTH: 350px; CURSOR: default";
onselectstart = function() { window.event.returnValue=false;}
innerHTML = '<DIV STYLE="PADDING: 10px; FONT-WEIGHT: bolder; COLOR: captiontext; BORDER-BOTTOM: white 2px groove; BACKGROUND-COLOR: activecaption"><center>Downloading ........ </center></DIV><DIV STYLE="PADDING: 8px;TEXT-ALIGN: center;">Please Wait for Loading This Page!!!!!</DIV><DIV STYLE="PADDING: 5px"><DIV ID="divProgressOuter" STYLE="BORDER: 1px solid threedshadow; WIDTH: 336px; HEIGHT: 15px"><DIV ID="divProgressInner" STYLE="COLOR: blue; TEXT-ALIGN: center; BACKGROUND-COLOR: infobackground; MARGIN: 0px; WIDTH: 0px; HEIGHT: 13px;"></DIV></DIV></DIV>'
}
document.body.appendChild(divProgressDialogObj);
document.body.runtimeStyle.cursor="wait";
var divModalObj = document.createElement("div");
with(divModalObj)
{
id="divModal";
style.cssText="BACKGROUND-COLOR: white; FILTER: alpha(opacity=75); LEFT: 0px; POSITION:absolute; TOP: 0px; Z-INDEX: 3";
onlick=function(){window.event.cancelBubble=true; window.event.returnValue=false;}
}
document.body.appendChild(divModalObj);
startLongProcess();
window.onload=stopLongProcess;
=====================method=============================
var NUMBER_OF_REPETITIONS = 40;
var nRepetitions = 0;
var g_oTimer = null;
function startLongProcess()
{
divProgressDialog.style.display = "";
resizeModal();
// Add a resize handler for the window
window.onresize = resizeModal;
continueLongProcess();
}
function updateProgress(nNewPercent)
{
// Update our pseudo progress bar
divProgressInner.style.width = (parseInt(divProgressOuter.style.width)
* nNewPercent / 100)+ "px";
}
function stopLongProcess()
{
if (g_oTimer != null)
{
// Clear the timer so we don't get called back an extra time
window.clearTimeout(g_oTimer);
g_oTimer = null;
}
// Hide the fake modal DIV
divModal.style.width = "0px";
divModal.style.height = "0px";
divProgressDialog.style.display = "none";
// Remove our event handlers
window.onresize = null;
window.onbeforeunload = null;
nRepetitions = 0;
}
function continueLongProcess()
{
// Set the timeout somewhere between 0 and .25 seconds
var nTimeoutLength = Math.random() * 250;
updateProgress(100 * nRepetitions / NUMBER_OF_REPETITIONS);
g_oTimer = window.setTimeout("continueLongProcess();", nTimeoutLength);
nRepetitions ++;
if(nRepetitions==NUMBER_OF_REPETITIONS)
nRepetitions=0;
}
function resizeModal()
{
// Resize the DIV which fakes the modality of the dialog DIV
divModal.style.width = document.body.scrollWidth;
divModal.style.height = document.body.scrollHeight;
// Re-center the dialog DIV
divProgressDialog.style.left = ((document.body.offsetWidth - divProgressDialog.offsetWidth) / 2);
divProgressDialog.style.top = ((document.body.offsetHeight - divProgressDialog.offsetHeight) / 2-60);
}
本文介绍了一种使用JavaScript创建模拟加载进度的方法,通过自定义的HTML和CSS实现了一个伪进度条效果,展示了如何通过定时器更新进度条状态来模拟长时间运行过程。
913

被折叠的 条评论
为什么被折叠?



