java 实现loading效果_JS基于Ajax实现的网页Loading效果代码

摘要:这篇JavaScript栏目下的“JS基于Ajax实现的网页Loading效果代码”,介绍的技术点是“loading效果、loading、ajax、js、实现、代码”,希望对大家开发技术学习和问题解决有帮助。

本文实例讲述了JS基于Ajax实现的网页Loading效果代码。分享给大家供大家参考,具体如下:

这是一款很不错的网页Loading效果,常用于Ajax交互式网页设计中,点击按钮即可弹出Loading框,若Loading框未加载完成时关闭网页,会弹出确认提示框,用于一些对安全性能要求高的网页交互处理中,比如付款操作。

运行效果截图如下:

0b0a72cd8e878f74c52768598fbf803b.png

在线演示地址如下:

具体代码如下:

很不错的网页Ajax Loading效果

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);

}

onselectstart="window.event.returnValue=false;">

加载中……

请稍等,网页正在处理中……

可能需要数秒钟.

ID="btnCancel" οnclick="stopLongProcess();" VALUE="取消">

STYLE="BACKGROUND-COLOR: white; FILTER: alpha(opacity=75); LEFT: 0px; POSITION:

absolute; TOP: 0px; Z-INDEX: 3"

οnclick="window.event.cancelBubble=true; window.event.returnValue=false;">

希望本文所述对大家JavaScript程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值