前端js實現彈出對話框實現進度條-10

<html>
<head>
<title>無標題文檔-學無憂(www.xue51.com)</title>
<SCRIPT language="javascript">
var NUMBER_OF_REPETITIONS = 40;
var nRepetitions = 0;
var g_oTimer = null;
//開始下載的方法
function startLongProcess()
{
   divProgressDialog.style.display = "";
   resizeModal();
   btnCancel.focus();
   // 設置窗口爲大小可更改模式
   window.onresize = resizeModal;
   //當用戶非正常中斷時,添加一個提示
   window.onbeforeunload = showWarning;
   continueLongProcess();
}
function updateProgress(nNewPercent)
{
   // 更改進度條的進度
   divProgressInner.style.width =
(parseInt(divProgressOuter.style.width)
      * nNewPercent / 100)+ "px";
}
//取消進度條的方法
function stopLongProcess()
{
   if (g_oTimer != null)
   {
      window.clearTimeout(g_oTimer);
      g_oTimer = null;
   }
   // Hide the fake modal DIV
   divModal.style.width = "0px";
   divModal.style.height = "0px";
   divProgressDialog.style.display = "none";
   // 移除窗體事件
   window.onresize = null;
   window.onbeforeunload = null;
   nRepetitions = 0;
}
//判斷進度是否執行完畢的方法
function continueLongProcess()
{
   if (nRepetitions < NUMBER_OF_REPETITIONS)
   {
      var nTimeoutLength = Math.random() * 250;
      updateProgress(100 * nRepetitions / NUMBER_OF_REPETITIONS);
      g_oTimer = window.setTimeout("continueLongProcess();",
nTimeoutLength);
      nRepetitions++;
   }
   else
   {
      stopLongProcess();
   }
}
function showWarning()
{
   //用戶非正常退出時的提示信息
   return "有一個應用程序正在運行,是否肯定要退出";
}
function resizeModal()
{
   divModal.style.width = document.body.scrollWidth;
   divModal.style.height = document.body.scrollHeight;
   divProgressDialog.style.left = ((document.body.offsetWidth -
divProgressDialog.offsetWidth) / 2);
   divProgressDialog.style.top = ((document.body.offsetHeight -
divProgressDialog.offsetHeight) / 2);
}
</SCRIPT>
</head>
<BODY STYLE="FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial, Helvetica">
<INPUT TYPE="BUTTON" VALUE="開始下載" onclick="startLongProcess();">
<!-- 開始下載 -->
<DIV STYLE="BORDER: buttonhighlight 2px outset; FONT-SIZE: 8pt; Z-INDEX:
4; FONT-FAMILY: Tahoma; POSITION: absolute; BACKGROUND-COLOR: buttonface;
DISPLAY: none; WIDTH: 350px; CURSOR: default" ID="divProgressDialog"
onselectstart="window.event.returnValue=false;">
   <DIV STYLE="PADDING: 3px; FONT-WEIGHT: bolder; COLOR: captiontext;
BORDER-BOTTOM: white 2px groove; BACKGROUND-COLOR: activecaption">
      下載對話框
   </DIV>
   <DIV STYLE="PADDING: 5px">
      正在下載,請等待.....
   </DIV>
   <DIV STYLE="PADDING: 5px">
      這個過程須要幾分鐘
   </DIV>
   <DIV STYLE="PADDING: 5px">
         <DIV ID="divProgressOuter" STYLE="BORDER: 1px solid threedshadow;
WIDTH: 336px; HEIGHT: 15px">
            <DIV ID="divProgressInner" STYLE="COLOR: white; TEXT-ALIGN:
center; BACKGROUND-COLOR: infobackground; MARGIN: 0px; WIDTH: 0px; HEIGHT:
13px;"></DIV>
         </DIV>
   </DIV>
   <DIV STYLE="BORDER-TOP: white 2px groove; PADDING-BOTTOM: 5px; PADDING-TOP: 3px;
BACKGROUND-COLOR: buttonface; TEXT-ALIGN: center">
         <INPUT STYLE="FONT-FAMILY: Tahoma; FONT-SIZE: 8pt" TYPE="button"
ID="btnCancel" onclick="stopLongProcess();" VALUE="取消">
   </DIV>
</DIV>
<!-- 結束下載 -->
<!-- BEGIN FAKE MODAL DIV-->
<DIV ID="divModal"
   STYLE="BACKGROUND-COLOR: white; FILTER: alpha(opacity=75); LEFT: 0px; POSITION:
 absolute; TOP: 0px; Z-INDEX: 3"
   onclick="window.event.cancelBubble=true; window.event.returnValue=false;">
</DIV>
<!-- END FAKE MODAL DIV -->
</body>
</html>javascript

相關文章
相關標籤/搜索