• 将数据加载时显示的图片和文字提成公共的--实现方法


    1. 页面引入loading.js。且在页面上添加<div id="loading"></div>
    2. 加载数据之前进行调用。调用方法如下:
    loading = new loadingObj($("#loading"), buildURI("images/"));
    loading.init();
    loading.show();
    $("#service_slist").hide();
    $("#listArea").empty();
    $("#pageArea").empty();
    $("#fw_empty").hide();
    if(typeof window.xhrCache != 'undefined') {
        typeof window.xhrCache.abort == 'function' && window.xhrCache.abort();
    }
    window.xhrCache = $.ajax( {
        type : "post",
        dataType : "text",
        url: url,
        data: data,
        success :     function(res){    
            loading.hide();
            ………………………………
            }
        });

    loading.js

    var loadingObj = function(viewObj, imgPathPrefix){
        var imgName = "loading_pa.gif";
        this.css = ".loading_box{background:url("+ imgPathPrefix + imgName +") center top no-repeat; padding-top:30px; 100%; font-size:12px; text-align:center; color:#cccccc;}";
        this.html = "<div class='loading_box'>正在加载中,请稍后...</div>";
        this.viewObj = viewObj;
    }
    
    loadingObj.prototype = {
        init: function(){
            var style = $("<style>"+ this.css +"</style>");
            var head = $("head").length > 0 ? $("head").eq(0) : $("head");
            style.appendTo(head);
            this.viewObj.html(this.html);
        },
        show: function(){
            this.viewObj.show();
        },
        hide: function(){
            this.viewObj.hide();
        }
    };
  • 相关阅读:
    Java vs Python
    Compiled Language vs Scripting Language
    445. Add Two Numbers II
    213. House Robber II
    198. House Robber
    276. Paint Fence
    77. Combinations
    54. Spiral Matrix
    82. Remove Duplicates from Sorted List II
    80. Remove Duplicates from Sorted Array II
  • 原文地址:https://www.cnblogs.com/kevin-yuan/p/3547751.html
Copyright © 2020-2023  润新知