哪位大佬幫忙解釋一下首頁模板上滑自動加載數(shù)據(jù)的JavaScript代碼?

科技 未結(jié) 1 1095
wang****uan55
wang****uan55 2022-01-19 16:30

/*!*http://bbs.design信息瀑布流內(nèi)容自動加載js代碼*/varIASCallbacks=function(){returnthis.list=[],this.fireStack=[],this.isFiring=!1,this.isDisabled=!1,this.fire=function(a){varb=a[0],c=a[1],d=a[2];this.isFiring=!0;for(vare=0,f=this.list.length;f>e;e++)if(void0!=this.list[e]&&!1===this.list[e].fn.apply(b,d)){c.reject();break}this.isFiring=!1,c.resolve(),this.fireStack.length&&this.fire(this.fireStack.shift())},this.inList=function(a,b){b=b||0;for(varc=b,d=this.list.length;d>c;c++)if(this.list[c].fn===a||a.guid&&this.list[c].fn.guid&&a.guid===this.list[c].fn.guid)returnc;return-1},this};IASCallbacks.prototype={add:function(a,b){varc={fn:a,priority:b};b=b||0;for(vard=0,e=this.list.length;e>d;d++)if(b>this.list[d].priority)returnthis.list.splice(d,0,c),this;returnthis.list.push(c),this},remove:function(a){for(varb=0;(b=this.inList(a,b))>-1;)this.list.splice(b,1);returnthis},has:function(a){returnthis.inList(a)>-1},fireWith:function(a,b){varc=jQuery.Deferred();returnthis.isDisabled?c.reject():(b=b||[],b=[a,c,b.slice?b.slice():b],this.isFiring?this.fireStack.push(b):this.fire(b),c)},disable:function(){this.isDisabled=!0},enable:function(){this.isDisabled=!1}},function(a){"usestrict";varb=-1,c=function(c,d){returnthis.itemsContainerSelector=d.container,this.itemSelector=d.item,this.nextSelector=d.next,this.paginationSelector=d.pagination,this.$scrollContainer=c,this.$container=window===c.get(0)?a(document):c,this.defaultDelay=d.delay,this.negativeMargin=d.negativeMargin,this.nextUrl=null,this.isBound=!1,this.isPaused=!1,this.isInitialized=!1,this.listeners={next:newIASCallbacks,load:newIASCallbacks,loaded:newIASCallbacks,render:newIASCallbacks,rendered:newIASCallbacks,scroll:newIASCallbacks,noneLeft:newIASCallbacks,ready:newIASCallbacks},this.extensions=[],this.scrollHandler=function(){if(this.isBound&&!this.isPaused){vara=this.getCurrentScrollOffset(this.$scrollContainer),c=this.getScrollThreshold();b!=c&&(this.fire("scroll",[a,c]),a>=c&&this.next())}},this.getItemsContainer=function(){returna(this.itemsContainerSelector)},this.getLastItem=function(){returna(this.itemSelector,this.getItemsContainer().get(0)).last()},this.getFirstItem=function(){returna(this.itemSelector,this.getItemsContainer().get(0)).first()},this.getScrollThreshold=function(a){varc;returna=a||this.negativeMargin,a=a>=0?-1*a:a,c=this.getLastItem(),0===c.length?b:c.offset().top+c.height()+a},this.getCurrentScrollOffset=function(a){varb=0,c=a.height();returnb=window===a.get(0)?a.scrollTop():a.offset().top,(-1!=navigator.platform.indexOf("iPhone")||-1!=navigator.platform.indexOf("iPod"))&&(c+=80),b+c},this.getNextUrl=function(b){returnb=b||this.$container,a(this.nextSelector,b).last().attr("href")},this.load=function(b,c,d){vare,f,g=this,h=[],i=+newDate;d=d||this.defaultDelay;varj={url:b};returng.fire("load",[j]),a.get(j.url,null,a.proxy(function(b){e=a(this.itemsContainerSelector,b).eq(0),0===e.length&&(e=a(b).filter(this.itemsContainerSelector).eq(0)),e&&e.find(this.itemSelector).each(function(){h.push(this)}),g.fire("loaded",[b,h]),c&&(f=+newDate-i,d>f?setTimeout(function(){c.call(g,b,h)},d-f):c.call(g,b,h))},g),"html")},this.render=function(b,c){vard=this,e=this.getLastItem(),f=0,g=this.fire("render",[b]);g.done(function(){a(b).hide(),e.after(b),a(b).fadeIn(400,function(){++f<b.length||(d.fire("rendered",[b]),c&&c())})})},this.hidePagination=function(){this.paginationSelector&&a(this.paginationSelector,this.$container).hide()},this.restorePagination=function(){this.paginationSelector&&a(this.paginationSelector,this.$container).show()},this.throttle=function(b,c){vard,e,f=0;returnd=function(){functiona(){f=+newDate,b.apply(d,g)}vard=this,g=arguments,h=+newDate-f;e?clearTimeout(e):a(),h>c?a():e=setTimeout(a,c)},a.guid&&(d.guid=b.guid=b.guid||a.guid++),d},this.fire=function(a,b){returnthis.listeners[a].fireWith(this,b)},this.pause=function(){this.isPaused=!0},this.resume=function(){this.isPaused=!1},this};c.prototype.initialize=function(){if(this.isInitialized)return!1;vara=!!("onscroll"inthis.$scrollContainer.get(0)),b=this.getCurrentScrollOffset(this.$scrollContainer),c=this.getScrollThreshold();returna?(this.hidePagination(),this.bind(),this.fire("ready"),this.nextUrl=this.getNextUrl(),b>=c?(this.next(),this.one("rendered",function(){this.isInitialized=!0})):this.isInitialized=!0,this):!1},c.prototype.reinitialize=function(){this.isInitialized=!1,this.unbind(),this.initialize()},c.prototype.bind=function(){if(!this.isBound){this.$scrollContainer.on("scroll",a.proxy(this.throttle(this.scrollHandler,150),this));for(varb=0,c=this.extensions.length;c>b;b++)this.extensions[b].bind(this);this.isBound=!0,this.resume()}},c.prototype.unbind=function(){if(this.isBound){this.$scrollContainer.off("scroll",this.scrollHandler);for(vara=0,b=this.extensions.length;b>a;a++)"undefined"!=typeofthis.extensions[a].unbind&&this.extensions[a].unbind(this);this.isBound=!1}},c.prototype.destroy=function(){this.unbind(),this.$scrollContainer.data("ias",null)},c.prototype.on=function(b,c,d){if("undefined"==typeofthis.listeners[b])thrownewError('Thereisnoeventcalled"'+b+'"');returnd=d||0,this.listeners[b].add(a.proxy(c,this),d),this},c.prototype.one=function(a,b){varc=this,d=function(){c.off(a,b),c.off(a,d)};returnthis.on(a,b),this.on(a,d),this},c.prototype.off=function(a,b){if("undefined"==typeofthis.listeners[a])thrownewError('Thereisnoeventcalled"'+a+'"');returnthis.listeners[a].remove(b),this},c.prototype.next=function(){vara=this.nextUrl,b=this;if(this.pause(),!a)returnthis.fire("noneLeft",[this.getLastItem()]),this.listeners.noneLeft.disable(),b.resume(),!1;varc=this.fire("next",[a]);returnc.done(function(){b.load(a,function(a,c){b.render(c,function(){b.nextUrl=b.getNextUrl(a),b.resume()})})}),c.fail(function(){b.resume()}),!0},c.prototype.extension=function(a){if("undefined"==typeofa.bind)thrownewError('Extensiondoesn\'thaverequiredmethod"bind"');return"undefined"!=typeofa.initialize&&a.initialize(this),this.extensions.push(a),this.isInitialized&&this.reinitialize(),this},a.ias=function(b){varc=a(window);returnc.ias.apply(c,arguments)},a.fn.ias=function(b){vard=Array.prototype.slice.call(arguments),e=this;returnthis.each(function(){varf=a(this),g=f.data("ias"),h=a.extend({},a.fn.ias.defaults,f.data(),"object"==typeofb&&b);if(g||(f.data("ias",g=newc(f,h)),a(document).ready(a.proxy(g.initialize,g))),"string"==typeofb){if("function"!=typeofg[b])thrownewError('Thereisnomethodcalled"'+b+'"');d.shift(),g[b].apply(g,d)}e=g}),e},a.fn.ias.defaults={item:".item",container:".listing",next:".next",pagination:!1,delay:600,negativeMargin:10}}(jQuery);varIASHistoryExtension=function(a){returna=jQuery.extend({},this.defaults,a),this.ias=null,this.prevSelector=a.prev,this.prevUrl=null,this.listeners={prev:newIASCallbacks},this.onPageChange=function(a,b,c){if(window.history&&window.history.replaceState){vard=history.state;history.replaceState(d,document.title,c)}},this.onScroll=function(a,b){varc=this.getScrollThresholdFirstItem();this.prevUrl&&(a-=this.ias.$scrollContainer.height(),c>=a&&this.prev())},this.onReady=function(){vara=this.ias.getCurrentScrollOffset(this.ias.$scrollContainer),b=this.getScrollThresholdFirstItem();a-=this.ias.$scrollContainer.height(),b>=a&&this.prev()},this.getPrevUrl=function(a){returna||(a=this.ias.$container),jQuery(this.prevSelector,a).last().attr("href")},this.getScrollThresholdFirstItem=function(){vara;returna=this.ias.getFirstItem(),0===a.length?-1:a.offset().top},this.renderBefore=function(a,b){varc=this.ias,d=c.getFirstItem(),e=0;c.fire("render",[a]),jQuery(a).hide(),d.before(a),jQuery(a).fadeIn(400,function(){++e<a.length||(c.fire("rendered",[a]),b&&b())})},this};IASHistoryExtension.prototype.initialize=function(a){varb=this;this.ias=a,jQuery.extend(a.listeners,this.listeners),a.prev=function(){returnb.prev()},this.prevUrl=this.getPrevUrl()},IASHistoryExtension.prototype.bind=function(a){a.on("pageChange",jQuery.proxy(this.onPageChange,this)),a.on("scroll",jQuery.proxy(this.onScroll,this)),a.on("ready",jQuery.proxy(this.onReady,this))},IASHistoryExtension.prototype.unbind=function(a){a.off("pageChange",this.onPageChange),a.off("scroll",this.onScroll),a.off("ready",this.onReady)},IASHistoryExtension.prototype.prev=function(){vara=this.prevUrl,b=this,c=this.ias;if(!a)return!1;c.pause();vard=c.fire("prev",[a]);returnd.done(function(){c.load(a,function(a,d){b.renderBefore(d,function(){b.prevUrl=b.getPrevUrl(a),c.resume(),b.prevUrl&&b.prev()})})}),d.fail(function(){c.resume()}),!0},IASHistoryExtension.prototype.defaults={prev:".prev"};varIASNoneLeftExtension=function(a){returna=jQuery.extend({},this.defaults,a),this.ias=null,this.uid=(newDate).getTime(),this.html=a.html.replace("{text}",a.text),this.showNoneLeft=function(){vara=jQuery(this.html).attr("id","ias_noneleft_"+this.uid),b=this.ias.getLastItem();b.after(a),a.fadeIn()},this};IASNoneLeftExtension.prototype.bind=function(a){this.ias=a,a.on("noneLeft",jQuery.proxy(this.showNoneLeft,this))},IASNoneLeftExtension.prototype.unbind=function(a){a.off("noneLeft",this.showNoneLeft)},IASNoneLeftExtension.prototype.defaults={text:"Youreachedtheend.",html:'<divclass="zhanzhuai-loading"><span>已經(jīng)加載到天涯海角,無內(nèi)容了!</span></div>'};varIASPagingExtension=function(){returnthis.ias=null,this.pagebreaks=[[0,document.location.toString()]],this.lastPageNum=1,this.enabled=!0,this.listeners={pageChange:newIASCallbacks},this.onScroll=function(a,b){if(this.enabled){varc,d=this.ias,e=this.getCurrentPageNum(a),f=this.getCurrentPagebreak(a);this.lastPageNum!==e&&(c=f[1],d.fire("pageChange",[e,a,c])),this.lastPageNum=e}},this.onNext=function(a){varb=this.ias.getCurrentScrollOffset(this.ias.$scrollContainer);this.pagebreaks.push([b,a]);varc=this.getCurrentPageNum(b)+1;this.ias.fire("pageChange",[c,b,a]),this.lastPageNum=c},this.onPrev=function(a){varb=this,c=b.ias,d=c.getCurrentScrollOffset(c.$scrollContainer),e=d-c.$scrollContainer.height(),f=c.getFirstItem();this.enabled=!1,this.pagebreaks.unshift([0,a]),c.one("rendered",function(){for(vard=1,g=b.pagebreaks.length;g>d;d++)b.pagebreaks[d][0]=b.pagebreaks[d][0]+f.offset().top;varh=b.getCurrentPageNum(e)+1;c.fire("pageChange",[h,e,a]),b.lastPageNum=h,b.enabled=!0})},this};IASPagingExtension.prototype.initialize=function(a){this.ias=a,jQuery.extend(a.listeners,this.listeners)},IASPagingExtension.prototype.bind=function(a){try{a.on("prev",jQuery.proxy(this.onPrev,this),this.priority)}catch(b){}a.on("next",jQuery.proxy(this.onNext,this),this.priority),a.on("scroll",jQuery.proxy(this.onScroll,this),this.priority)},IASPagingExtension.prototype.unbind=function(a){try{a.off("prev",this.onPrev)}catch(b){}a.off("next",this.onNext),a.off("scroll",this.onScroll)},IASPagingExtension.prototype.getCurrentPageNum=function(a){for(varb=this.pagebreaks.length-1;b>0;b--)if(a>this.pagebreaks[b][0])returnb+1;return1},IASPagingExtension.prototype.getCurrentPagebreak=function(a){for(varb=this.pagebreaks.length-1;b>=0;b--)if(a>this.pagebreaks[b][0])returnthis.pagebreaks[b];returnnull},IASPagingExtension.prototype.priority=500;varIASSpinnerExtension=function(a){returna=jQuery.extend({},this.defaults,a),this.ias=null,this.uid=(newDate).getTime(),this.src=a.src,this.html=a.html.replace("{src}",this.src),this.showSpinner=function(){vara=this.getSpinner()||this.createSpinner(),b=this.ias.getLastItem();b.after(a),a.fadeIn()},this.showSpinnerBefore=function(){vara=this.getSpinner()||this.createSpinner(),b=this.ias.getFirstItem();b.before(a),a.fadeIn()},this.removeSpinner=function(){this.hasSpinner()&&this.getSpinner().remove()},this.getSpinner=function(){vara=jQuery("#ias_spinner_"+this.uid);returna.length>0?a:!1},this.hasSpinner=function(){vara=jQuery("#ias_spinner_"+this.uid);returna.length>0},this.createSpinner=function(){vara=jQuery(this.html).attr("id","ias_spinner_"+this.uid);returna.hide(),a},this};IASSpinnerExtension.prototype.bind=function(a){this.ias=a,a.on("next",jQuery.proxy(this.showSpinner,this)),a.on("render",jQuery.proxy(this.removeSpinner,this));try{a.on("prev",jQuery.proxy(this.showSpinnerBefore,this))}catch(b){}},IASSpinnerExtension.prototype.unbind=function(a){a.off("next",this.showSpinner),a.off("render",this.removeSpinner);try{a.off("prev",this.showSpinnerBefore)}catch(b){}},IASSpinnerExtension.prototype.defaults={html:'<divclass="zhanzhuai-loading"><divclass="load-iconload-icon-1"></div><divclass="load-iconload-icon-2"></div><divclass="load-iconload-icon-3"></div><span>玩命加載中...</span></div>'};varIASTriggerExtension=function(a){returna=jQuery.extend({},this.defaults,a),this.ias=null,this.html=a.html.replace("{text}",a.text),this.htmlPrev=a.htmlPrev.replace("{text}",a.textPrev),this.enabled=!0,this.count=0,this.offset=a.offset,this.$triggerNext=null,this.$triggerPrev=null,this.showTriggerNext=function(){if(!this.enabled)return!0;if(!1===this.offset||++this.count<this.offset)return!0;vara=this.$triggerNext||(this.$triggerNext=this.createTrigger(this.next,this.html)),b=this.ias.getLastItem();returnb.after(a),a.fadeIn(),!1},this.showTriggerPrev=function(){if(!this.enabled)return!0;vara=this.$triggerPrev||(this.$triggerPrev=this.createTrigger(this.prev,this.htmlPrev)),b=this.ias.getFirstItem();returnb.before(a),a.fadeIn(),!1},this.onRendered=function(){this.enabled=!0},this.createTrigger=function(a,b){varc,d=(newDate).getTime();returnb=b||this.html,c=jQuery(b).attr("id","ias_trigger_"+d),c.hide(),c.on("click",jQuery.proxy(a,this)),c},this};IASTriggerExtension.prototype.bind=function(a){this.ias=a,a.on("next",jQuery.proxy(this.showTriggerNext,this),this.priority),a.on("rendered",jQuery.proxy(this.onRendered,this),this.priority);try{a.on("prev",jQuery.proxy(this.showTriggerPrev,this),this.priority)}catch(b){}},IASTriggerExtension.prototype.unbind=function(a){a.off("next",this.showTriggerNext),a.off("rendered",this.onRendered);try{a.off("prev",this.showTriggerPrev)}catch(b){}},IASTriggerExtension.prototype.next=function(){this.enabled=!1,this.ias.pause(),this.$triggerNext&&(this.$triggerNext.remove(),this.$triggerNext=null),this.ias.next()},IASTriggerExtension.prototype.prev=function(){this.enabled=!1,this.ias.pause(),this.$triggerPrev&&(this.$triggerPrev.remove(),this.$triggerPrev=null),this.ias.prev()},IASTriggerExtension.prototype.defaults={text:"加載更多",html:'<divclass="zhanzhuai-ajax-more"style="text-align:center;cursor:pointer;"><a>{text}</a></div>',textPrev:"Loadpreviousitems",htmlPrev:'<divclass="ias-triggerias-trigger-prev"style="text-align:center;cursor:pointer;"><a>{text}</a></div>',offset:0},IASTriggerExtension.prototype.priority=1e3;

上面代碼是自別的網(wǎng)站上扒下來的,研究用的。功能仿知乎首頁信息瀑布流功能。

相關(guān)標(biāo)簽:
1條回答
  • 2022-01-19 17:23

    這種jquery插件都有現(xiàn)成得,自己集成調(diào)用數(shù)據(jù)即可,沒必要研究別人內(nèi)部怎么實現(xiàn)

    0 討論(0)
提交回復(fù)
最新問題
宏基E146D家用投影機有非常大的聲響 1
做輸卵管造影大約多少錢 1
央視是哪個頻道 3
什么牌子的電視盒子比較好? 1
哪里醫(yī)院專治輸卵管堵塞好 1
9K金是純金嗎?9K金佩戴時間長了會不會掉色? 4
索尼PS VR2被曝2022年下半年開始量產(chǎn) 1
剛買的黃金項鏈印記是z j 1千足金是什么意思 1
有輸卵管不孕如何治療 1
為什么說一代試管養(yǎng)囊生男孩比女孩的幾率多? 1
猜你喜歡
長沙三代試管一次全部一起費用多少?3萬費用夠嗎?
野生龍葵是什么?它的功效與作用有哪些?
哪的泰國試管嬰兒服務(wù)機構(gòu)費用低!附影響因素介紹!
第三代試管生孩多少費用在泰國,讓您輕松面對!
北京私人婦產(chǎn)科醫(yī)院可以做試管嗎!費用概覽!
鄭州第三代試管做一次多少錢?費用因個人而異?
進(jìn)口和國產(chǎn)的溴隱亭價格分別是多少?
第三代試管大概要多少錢?附洗精成功率及好處
都有哪些情況醫(yī)生不建議打自費疫苗,為什么?
決定試管嬰兒的成功因素有哪些,要準(zhǔn)備多少錢!
熱門文章
國內(nèi)三大助孕公司排名分享,國內(nèi)助孕機構(gòu)詳細(xì)介紹
泰國做試管口碑比較好的醫(yī)院盤點
天津三大助孕公司有哪家?
2025年泰國三代試管醫(yī)院哪家好?
國外三代試管嬰兒成功率高醫(yī)院有哪幾家?國外試管醫(yī)院大全整理
山東私立醫(yī)院試管成功率數(shù)據(jù)已更新,快看看哪家高
2025重慶私立醫(yī)院三代試管成功率和費用明細(xì)數(shù)據(jù)公布!
單身女性泰國試管嬰兒費用大概多少?
哪家泰國三代試管嬰兒成功率好:快來掌握要點
合肥私立醫(yī)院能不能做三代試管?一文告訴你實情
廣告合作方 廣告申請