0

我正在尝试创建一个加载函数,它构建一个基本 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();
});
4

1 回答 1

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

http://jsfiddle.net/FVcpH/1/

于 2012-11-03T07:00:23.810 回答