js 數據加載loading封裝

<!-- 模態框(Modal) -->
<div class="modal fade" id="qst_loading" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="z-index: 9999">
    <div class="modal-dialog">
        <div class="modal-content" style="width: 0px; text-align: center">
            <div class="modal-body" >
            </div>
        </div><!-- /.modal-content -->
        {{ image("static/background/image/loading.gif", "alt":"loading", "style":"max-width: 200px; margin:200px 100px 100px 200px") }}
    </div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
/*
* 一、這個封裝外層包裹自執行函數,只要引入此文件,js 就會自動執行
* 二、if('undefined' == typeof QstLoading) 首先判斷QstLoading函數名有沒有被使用,避免覆蓋其餘方法
* 三、定義一個匿名函數,使用new構造函數,意思是建立一個新的對象QstLoading ,並分配一個新地址,改變this指向,指向QstLoading ,(this )
* 四、爲新對象添加屬性show和hide
* 五、QstLoading 沒有聲明,成爲全局對象(不建議此種方法成爲全局)
*/



/*
* 一、這個封裝外層包裹自執行函數,只要引入此文件,js 就會自動執行
* 二、if('undefined' == typeof QstLoading) 首先判斷QstLoading函數名有沒有被使用,避免覆蓋其餘方法
* 三、定義一個匿名函數,使用new構造函數,意思是建立一個新的對象QstLoading ,並分配一個新地址,改變this指向,指向QstLoading ,(this )
* 四、爲新對象添加屬性show和hide
* 五、QstLoading 沒有聲明,成爲全局對象(不建議此種方法成爲全局)
*/
$(function() {
        if('undefined' == typeof QstLoading){
            QstLoading = new function () {
                var _modal = $('#qst_loading');
                $(_modal).modal({
                    keyboard: false,
                    backdrop: 'static',
                    show: false
                });
                this.show = function () {
                    $(_modal).modal("show");
                };
                this.hide = function () {
                    $(_modal).modal('hide');
                }
            }();
        }
    });
相關文章
相關標籤/搜索