JSLoading功能的简单实现
我们经常在浏览⽹页的时候会看到数据在加载时,出现的LOADING提⽰。其实这个功能原理是很简单的,就是⼀个DIV遮盖当前页⾯,然后Loading就在遮盖DIV层上展⽰出来,现在我们来动⼿实现⼀下。
复制代码代码如下:
<div class="current"><a href="#" onclick="showLoading()">Loading</a></div>
复制代码代码如下:
<div id="over" class="over"></div>
复制代码代码如下:
<div id="layout" class="layout"><img src="//img.jbzj/file_images/article/201311/2013112931.gif" alt="" /></div>
整体代码:
复制代码代码如下:
<!DOCTYPE html>
<html xmlns="/1999/xhtml">js arguments
<head>
<title></title>
<style type="text/css">
.current a {
font-size: 20px;
}
.over {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #f5f5f5;
opacity:0.5;
z-index: 1000;
}
.layout {
display: none;
position: absolute;
top: 40%;
left: 40%;
width: 20%;
height: 20%;
z-index: 1001;
text-align:center;
}
</style>
<script type="text/javascript">
function showLoading()
{
}
</script>
</head>
<body>
<div class="current"><a href="#" onclick="showLoading()">Loading</a></div>
<div id="over" class="over"></div>
<div id="layout" class="layout"><img src="//img.jbzj/file_images/article/201311/2013112931.gif" alt="" /></div>
</body>
</html>
最终效果:
在⽹上还看到另外⼀种实现⽅式,感觉思路不错,就是利⽤JS不断的改变html标签的value值,达到加载提⽰的效果,根据他的思路我⾃⼰实现了下,代码如下:
复制代码代码如下:
<!DOCTYPE html>
<html xmlns="/1999/xhtml">
<head>
<title></title>
<!-- <script src="Scripts/jquery-1.8.2.js"></script>-->
<style type="text/css">
#tb {
width: 100%;
height: 100%;
line-height: 10px;
}
#tb tr td {
text-align: center;
}
.
progressbar {
font-family: Arial;
font-weight: bolder;
color: gray;
background-color: white;
padding: 0px;
border-style: none;
}
.percent {
font-family: Arial;
color: gray;
text-align: center;
border-width: medium;
border-style: none;
}
</style>
<script type="text/javascript">
var bar = 0;
var step = "||";
/*
*第⼀种⽅式即:$(document).ready(function(){.....});
*/
/
/$(function () {
// progress();
//});
/*
*第⼆种⽅式
*/
//load = function () {
// progress();
//}
/*
*第三种⽅式模拟 $(document).ready(function(){.....});
*/
(function () {
var ie = !!(window.attachEvent && !window.opera);
var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525); var fn = [];
var run = function () { for (var i = 0; i < fn.length; i++) fn[i](); };
var d = document;
if (!ie && !wk && d.addEventListener)
return d.addEventListener('DOMContentLoaded', f, false);
if (fn.push(f) > 1) return;
if (ie)
(function () {
try { d.documentElement.doScroll('left'); run(); }
catch (err) { setTimeout(arguments.callee, 0); }
})();
else if (wk)
var t = setInterval(function () {
if (/^(loaded|complete)$/.adyState))
clearInterval(t), run();
}, 0);
};
})();
progress();
});
function progress() {
bar = bar + 2;
step = step + "||";
if (bar <= 98) {
setTimeout("progress()", 100);
}
}
</script>
</head>
<body>
<table id="tb">
<tr>
<td>
<input type="text" size="50" class="percent" id="percent" /></td>
</tr>
<tr>
<td>
<input type="text" size="50" class="progressbar" id="progressbar" /></td> </tr>
</table>
</body>
</html>
最终效果:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论