/*** @author wsf 滚动按需加载*/
;
(function (w,$){var jutil = null;//工具类/*** 滚动按需加载对象*/function demandLoader (){this.startLoadFlag = {};//是否开始加载this.allLoaded = false;//是否全部加载完成//分批加载函数this.batch = {"fun1":this.loadCustTree,"fun2":this.prevLoadActAndOpt,"fun3":this.prevLoadActAndOpt//等等};}/*** 原型对象*/demandLoader.prototype = {constructor:demandLoader,//构造函数//加载后台数据getJson:function (url,param,callback,othargs){var that = this;$.getJSON(url,param,function (data){callback.call(that,data,othargs);});},//开始加载startLoad:function(){var scrolltop = arguments[0];//页面滚动高度jutil = arguments[1];//jsUtilif(typeof idxpos != "object"){return false;}var catalog1 = idxpos.h2IdxPos;//一级目录位置var catalog2 = idxpos.h3IdxPos;//二级目录位置this.loadCataCommon(catalog1, scrolltop);//一级目录延迟加载this.loadCataCommon(catalog2, scrolltop);//二级目录延迟加载},// 目录公共加载方法loadCataCommon : function(catalog, scrolltop) {for ( var i in catalog) {var cl = catalog[i];// 目录var text = cl.text;// 加载哪一部分var catalogtop = cl.top;// 目录位置(父目录)var difTop = scrolltop - catalogtop;// 高度差if (difTop>0&&this.startLoadFlag[text] == undefined) {var loadFn = this.batch[text];// 加载处理函数if (jutil.isFunction(loadFn)) {this.startLoadFlag[text] = "startload";// 开始加载loadFn.call(this, text);} }}},//加载客户关系树loadCustTree:function (){this.startLoadFlag[text] = "endload";//加载完成this.endLoad();//加载结束},//加载收入信息loadIncome:function (){this.startLoadFlag[text] = "endload";//加载完成this.endLoad();//加载结束},//预先加载活动,机会信息prevLoadActAndOpt:function (text){this.startLoadFlag[text] = "endload";//加载完成this.endLoad();//加载结束},//加载地址信息loadDz:function (text){this.startLoadFlag[text] = "endload";//加载完成this.endLoad();//加载结束},//结束加载endLoad:function (){$._initCatelogPos();//重新计算目录位置this.allLoaded = true;for(var catalotnm in this.batch){this.allLoaded = this.allLoaded && (this.startLoadFlag[catalotnm] == "endload");}}}w.demandLoader = demandLoader;//外部调用入口
})(window,jQuery);调用方式/*** 窗口滚动事件*/function winScroll(){scrollTop = $(win).scrollTop();if(!_demandLoader.allLoaded){_demandLoader.custid = $("#custid").val();//当前客户id//还没有加载过_jsUtils.throttle(function (){_demandLoader.startLoad.call(_demandLoader,scrollTop,_jsUtils);//开始按需加载},110);}}$(win).scroll(winScroll);//窗口滚动监听