JS基于Ajax實(shí)現(xiàn)的網(wǎng)頁(yè)Loading效果代碼
本文實(shí)例講述了JS基于Ajax實(shí)現(xiàn)的網(wǎng)頁(yè)Loading效果代碼。分享給大家供大家參考,具體如下:
這是一款很不錯(cuò)的網(wǎng)頁(yè)Loading效果,常用于Ajax交互式網(wǎng)頁(yè)設(shè)計(jì)中,點(diǎn)擊按鈕即可彈出Loading框,若Loading框未加載完成時(shí)關(guān)閉網(wǎng)頁(yè),會(huì)彈出確認(rèn)提示框,用于一些對(duì)安全性能要求高的網(wǎng)頁(yè)交互處理中,比如付款操作。
運(yùn)行效果截圖如下:
在線(xiàn)演示地址如下:
http://demo.jb51.net/js/2015/js-ajax-web-loading-style-codes/
具體代碼如下:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>很不錯(cuò)的網(wǎng)頁(yè)Ajax Loading效果</title> </head> <BODY STYLE="FONT-SIZE: 10pt; FONT-FAMILY: Verdana, Arial, Helvetica"> <SCRIPT LANGUAGE="JScript"> 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"; // Remove our event handlers 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 "Navigating to a different page or refreshing the window could cause you to lose precious data.\n\nAre you*absolutely* certain you want to do this?"; } 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> <INPUT TYPE="BUTTON" VALUE="Click Me!" onclick="startLongProcess();"> <!-- BEGIN PROGRESS DIALOG --> <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"> 請(qǐng)稍等,網(wǎng)頁(yè)正在處理中…… </DIV> <DIV STYLE="PADDING: 5px"> 可能需要數(shù)秒鐘. </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> <!-- END PROGRESS DIALOG --> <!-- 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>
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
web3.js調(diào)用鏈上的方法操作NFT區(qū)塊鏈MetaMask詳解
這篇文章主要為大家介紹了web3.js調(diào)用鏈上的方法操作NFT區(qū)塊鏈MetaMask詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08JavaScript使用pop方法移除數(shù)組最后一個(gè)元素用法實(shí)例
這篇文章主要介紹了JavaScript使用pop方法移除數(shù)組最后一個(gè)元素,實(shí)例分析了javascript中pop方法的使用技巧,需要的朋友可以參考下2015-04-04javascript之textarea打字機(jī)效果提示代碼推薦
非常不錯(cuò)的提示輸入內(nèi)容,動(dòng)態(tài)的提示,給人親切感2008-09-09對(duì)js eval()函數(shù)的一些見(jiàn)解
下面小編就為大家?guī)?lái)一篇對(duì)js eval()函數(shù)的一些見(jiàn)解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08簡(jiǎn)單實(shí)現(xiàn)輪播圖效果的實(shí)例
下面小編就為大家?guī)?lái)一篇簡(jiǎn)單實(shí)現(xiàn)輪播圖效果的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-07-07JavaScript實(shí)現(xiàn)添加、查找、刪除元素
這篇文章主要匯總介紹了JavaScript實(shí)現(xiàn)添加、查找、刪除元素的方法,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2015-07-07