我正在尝试创建一个加载函数,该函数构建一个基本DOM,其中加载动画垂直居中,另一种方法是销毁它。我不知道如何实现隐藏!我不想创建另一个单独的函数来销毁加载DOM!我想将它们都放在一个名称空间下!
$(document).ready(function() {
$.extend({
loading:function(status) {
var _status=status || 'Loading';
var $this= $('<div class="loadnote"><img src="loadinfo.net.gif" width="16" height="16" /><span>'+_status+'</span></div>').appendTo($('body'));
function center() {
var w = $this.width();
w+= parseInt($this.css('padding-left'))+parseInt($this.css('padding-right'));
var w_box = $(window).width();
var w_total = (w_box - w)/2;
var css = {
"left": w_total+'px'
};
$this.css(css)
}
center();
function hide() {
$this.remove();
}
//return hide();
}
});
$.loading();
//$.loading().hide();
});
答案 0 :(得分:1)
尝试:
$.extend({
loading:function(status) {
var _status=status || 'Loading';
var $this= $('<div class="loadnote"><img src="loadinfo.net.gif" width="16" height="16" /><span>'+_status+'</span></div>').appendTo($('body'));
function center() {
var w = $this.width();
w+= parseInt($this.css('padding-left'))+parseInt($this.css('padding-right'));
var w_box = $(window).width();
var w_total = (w_box - w)/2;
var css = {
"left": w_total+'px'
};
$this.css(css)
}
center();
function hide() {
$this.remove();
}
return {hide: hide};
}
});
var retval = $.loading();
retval.hide();