jquery进度条代码模拟效果

发布时间:2020-01-18编辑:脚本学堂
一个jquery进度条代码的模拟例子,这里提供的jquery进度条,并没有与后台数据同步,不是真正的进度条效果,只是作为学习jquery进度条的实现方法,研究下。

jquery/jindutiao/ target=_blank class=infotextkey>jquery进度条代码

引入jquery1.3以上的版本。
导入jquery进度条脚本:jquery.processing.plugin.js

在脚本中添加:
 

$(document).progressDialog.showDialog("正在请求,请等待..."); 

解除jquery进度条的方法:
 

$(document).progressDialog.hideDialog(); 

附,jquery进度条插件的核心代码。
 

复制代码 代码示例:

jquery.processing.plugin.js
/**
 * progress-Dialog for jQuery
 * Written by vakin Jiang (mailto: chiang.www@gmail.com)
 * @author vakin
 * @version 1.0
 *
 * @example
 * $(document).progressDialog.showDialog();
 *
 *  $.ajax({
.....
complete:function(data){
  $(document).progressDialog.hideDialog();
  //do something
}
});
 **/
(function($) {
$.fn.progressDialog = function() {

};

$.fn.progressDialog.showDialog = function(text) {
text = text || "Loading,Please wait..."
createElement(text);
setPosition();
waterfall.appendTo("body");
$(window).bind('resize', function() {
setPosition();
});
}

$.fn.progressDialog.hideDialog = function(text) {
waterfall.remove();
}

function createElement(text) {
if (!waterfall) {
waterfall = $(document.createElement("div"));
waterfall.attr("id", "waterfall");
waterfall.css( {
"height" : "100%",
"width" : "100%",
"filter" : "alpha(opacity = 50)",
"-moz-opacity" : "0.5",
"opacity" : "0.5",
"background-color" : "#CCCCCC",
"position" : "absolute",
"left" : "0px",
"top" : "0px"
});
}
if (!loadDiv) {
loadDiv = document.createElement("div");
}
$(loadDiv).appendTo(waterfall);

var content = " <div style='width:" +width+ "px; height:" +Height+ "px;'><div style='width:100%; height:30px; line-height:31px;padding-left:15px;font-weight:bolder; color:#929292;'>"+text+"</div><div align='center'><img src='/wmba/theme/standard/images/blue/loading.gif' border='0'/></div></div>";
$(loadDiv).html(content);
}

//jquery
function setPosition() {
var leftOffset = ($(document).width() - width) / 2;
var topOffset = ($(document).height() - Height) / 2;
$(loadDiv).css( {
"position" : "absolute",
"height" : Height + "px",
"width" : width + "px",
"left" : leftOffset + "px",
"top" : topOffset + "px"
});
}

var waterfall;
var loadDiv;
var width = 290;
var Height = 60;
})(jQuery);