-
Notifications
You must be signed in to change notification settings - Fork 0
/
fkscrollrefresh.min.js
2 lines (2 loc) · 7.6 KB
/
fkscrollrefresh.min.js
1
2
/*! FKScrollRefresh v1.2 | FeikeWrold | www.fk68.net */
!function(a){var b={mode:"all",slideSelector:"",wrapperClass:"fk-scrollRefresh",mouseWheel:!0,wheelThreshold:2,swipeThreshold:50,preventDefaultSwipeY:!0,headText:"下拉刷新",footerText:"上拉刷新",refreshIni:"释放刷新",refreshNow:"正在刷新....",refreshOk:"刷新成功",imgRefresh:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAaCAMAAAB1owf/AAAAM1BMVEUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACjBUbJAAAAEHRSTlMA3z/vny9Pj28fr39fv88PqUI94gAAAKJJREFUKM99klsShCAMBCc8BBXduf9pFxHZQLH2J82QFAmmrFAsTpgRtwDhVOfChkSyhRwHohYSTCbc4eMnbERlK+pTalzCP8KzkJCRW+iIPVKNJMxwpGCKJXcM7OU2SQNNrYCVpB+NeTUvr0EmHYS//QrppiLWCumwzGxNeEtKvdH/qX2aWtlF4iUCCifHyblWcCCoYUW9IUa1v3dbpfCY8AU1WAzsQu60BgAAAABJRU5ErkJggg==",imgScroll:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAgBAMAAAAVss41AAAAHlBMVEUAAAAzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzOYOQtZAAAACXRSTlMA8DBcoEDbiyDW1p4HAAAAfElEQVQY09XRKxLCQBBF0VcBgUzh4mAHY3FYJChwWByWXRA+Sd3dpjuZqa4sIde9PrI1dm6TooZaEbyXvDaXsqqrdOCZ14sk+E1rDbWAo+Cjk58ejvA34q69oy2jdqeqgR46YCsZ5ozkaGUyDAp0CkxS4FelW5C1KjT/2AARalofLH+YhgAAAABJRU5ErkJggg==",onScrollAct:function(){},onRefreshStop:function(){}};a.fn.FKScrollRefresh=function(c){var d,e,g,h,i,j,k,l,m,n,o,p,q;return 0==this.length?this:this.length>1?(this.each(function(){a(this).FKScrollRefresh(c)}),this):(d={},e=this,a(window).width(),g=a(window).height(),h=function(){d.settings=a.extend({},b,c),d.working=!1,d.viewport=e,i()},i=function(){d.initialized=!0,l(),d.settings.mouseWheel&&j()},j=function(){d.mousewheel={up:0,down:0},d.viewport.bind("mousewheel",k)},k=function(b){var c,f,h,i,j,k,l,m,n;if(!d.working&&(d.startedAt&&(c=new Date,c.getTime()-d.startedAt.getTime(),c.getTime()-d.startedAt.getTime()>300&&(d.mousewheel={up:0,down:0},d.working=!1)),d.startedAt=new Date,f=d.viewport.scrollTop(),h=d.viewport[0].scrollHeight,i="body"==d.viewport.selector?g:d.viewport.height(),j=h-i-f,d.scroll_Top=f,d.scroll_Bot=j,d.Content_H=h,0==d.scroll_Top||0==d.scroll_Bot))if(d.rotINT_stop=!1,k='<div class="imgScroll" style="width:5%; display: inline-block;"><img src="'+d.settings.imgRefresh+'" style="vertical-align:middle; width:100%;" /></div>',l='<span class="txtScroll" style="margin-left: 20px; color:#333;">'+d.settings.refreshNow+"</span>",m='<div style="width:100%;height:'+d.settings.swipeThreshold+"px;margin: 0;padding: 0;border: 0;background: #eee;text-align: center;font-size: 1em;overflow: hidden;line-height: "+d.settings.swipeThreshold+'px;" class="'+d.settings.wrapperClass+'">'+k+l+"</div>",b=window.event||b,n=Math.max(-1,Math.min(1,b.wheelDelta||-b.deltaY||-b.detail)),0>n){if("first"==d.settings.mode)return;d.mousewheel.up+=n,Math.abs(d.mousewheel.up)>d.settings.wheelThreshold&&(d.working=!0,0==d.scroll_Bot&&d.viewport.append(m),"body"==d.viewport.selector?a("body").scrollTop(99999):d.viewport.scrollTop(99999),d.viewtips=d.viewport.find("."+d.settings.wrapperClass),d.imgScroll=d.viewtips.find(".imgScroll"),d.txtScroll=d.viewtips.find(".txtScroll"),d.txtScroll.data("txthtm",d.txtScroll.html()),q(d.viewtips,"last"))}else{if("last"==d.settings.mode)return;d.mousewheel.down+=n,Math.abs(d.mousewheel.down)>d.settings.wheelThreshold&&(d.working=!0,0==d.scroll_Top&&d.viewport.prepend(m),d.viewtips=d.viewport.find("."+d.settings.wrapperClass),d.imgScroll=d.viewtips.find(".imgScroll"),d.txtScroll=d.viewtips.find(".txtScroll"),d.txtScroll.data("txthtm",d.txtScroll.html()),q(d.viewtips,"first"))}},l=function(){d.touch={start:{x:0,y:0},end:{x:0,y:0}},d.viewport.bind("touchstart",m)},m=function(a){var b,c,e,f,h,i,j,k,l,m,o;d.working||(b=d.viewport.scrollTop(),c=d.viewport[0].scrollHeight,e="body"==d.viewport.selector?g:d.viewport.height(),f=c-e-b,d.scroll_Top=b,d.scroll_Bot=f,d.Content_H=c,(0==d.scroll_Top||0==d.scroll_Bot)&&(d.rotINT_stop=!1,h=a.originalEvent,d.touch.start.x=h.changedTouches[0].screenX,d.touch.start.y=h.changedTouches[0].screenY,i='<div class="imgScroll" style="width:5%; display: inline-block;"><img src="'+d.settings.imgScroll+'" style="vertical-align:middle; width:100%;" /></div>',j='<span class="txtScroll" style="margin-left: 20px; color:#333;">'+d.settings.headText+"</span>",k='<div class="imgScroll" style="width:5%;display: inline-block;"><img src="'+d.settings.imgScroll+'" style="vertical-align:middle;width:100%;-webkit-transform: rotate(180deg); transform: rotate(180deg); " /></div>',l='<span class="txtScroll" style="margin-left: 20px; color:#333;">'+d.settings.footerText+"</span>",m='<div style="width:100%;height:0;margin: 0;padding: 0;border: 0;background: #eee;text-align: center;font-size: 1em;overflow: hidden;line-height: '+d.settings.swipeThreshold+'px;" class="'+d.settings.wrapperClass+'">'+i+j+"</div>",o='<div style="width:100%;height:0;margin: 0;padding: 0;border: 0;background: #eee;text-align: center;font-size: 1em;overflow: hidden;line-height: '+d.settings.swipeThreshold+'px;" class="'+d.settings.wrapperClass+'">'+k+l+"</div>",0==d.scroll_Top?(d.viewport.prepend(m),d.viewtips=d.viewport.find("."+d.settings.wrapperClass+":first")):0==d.scroll_Bot&&(d.viewport.append(o),d.viewtips=d.viewport.find("."+d.settings.wrapperClass+":last")),d.viewport.bind("touchmove",n),d.viewport.bind("touchend",p)))},n=function(a){var f,g,b=a.originalEvent,c=b.changedTouches[0].screenX-d.touch.start.x,e=b.changedTouches[0].screenY-d.touch.start.y;if(f=d.settings.preventDefaultSwipeY?e:c,0>f){if("first"==d.settings.mode)return;if(0!=d.scroll_Bot)return}else{if("last"==d.settings.mode)return;if(0!=d.scroll_Top)return}a.preventDefault(),d.working||d.viewtips.show(),d.working=!0,d.params=Math.abs(f),d.viewtips.height(d.params),d.viewport.css("margin-top",f+"px"),d.params>d.settings.swipeThreshold?d.scroll_Act||(d.imgScroll=d.viewtips.find(".imgScroll"),d.txtScroll=d.viewtips.find(".txtScroll"),d.txtScroll.data("txthtm",d.txtScroll.html()),d.scroll_Act=!0,d.clear_rotate=!0,o(d.imgScroll,180,0),d.txtScroll.html(d.settings.refreshIni)):d.scroll_Act&&(d.clear_rotate=!0,o(d.imgScroll,0,180),d.scroll_Act=!1,g=d.txtScroll.data("txthtm"),d.txtScroll.html(g))},o=function(a,b,c){d.clear_rotate&&clearInterval(d.rotINT),d.clear_rotate=!1;var e=c||0;d.rotINT=setInterval(function(){b>e?e+=10:e-=10,d.rotINT_stop&&(e=0,clearInterval(d.rotINT)),a.css({"-webkit-transform":"rotate("+e+"deg)","-moz-transform":"rotate("+e+"deg)",transform:"rotate("+e+"deg)"}),e==b&&clearInterval(d.rotINT),(360==e||-360==e)&&(e=0)},10)},p=function(a){var b,c;if(d.viewport.unbind("touchmove",n),d.viewport.unbind("touchend",p),d.working=!1,b=a.originalEvent,d.touch.end.x=b.changedTouches[0].screenX,d.touch.end.y=b.changedTouches[0].screenY,c=0,c=d.settings.preventDefaultSwipeY?d.touch.end.y-d.touch.start.y:d.touch.end.x-d.touch.start.x,0>c){if("first"==d.settings.mode)return;if(0!=d.scroll_Bot)return}else{if("last"==d.settings.mode)return;if(0!=d.scroll_Top)return}Math.abs(c)>d.settings.swipeThreshold?(d.viewtips.height(d.settings.swipeThreshold),d.working=!0,0>c?q(d.viewtips,"last"):q(d.viewtips,"first")):(d.clear_rotate=!0,d.viewtips.slideUp(200,function(){var a=d.viewport.find("."+d.settings.wrapperClass);a.remove()}),d.viewport.animate({"margin-top":"0px"},200))},q=function(a,b){("first"!=d.settings.mode||"last"!=b)&&("last"!=d.settings.mode||"first"!=b)&&(d.settings.onRefreshStop=e.onRefreshStop,d.imgScroll.find("img").attr("src",d.settings.imgRefresh),d.txtScroll.html(d.settings.refreshNow),d.clear_rotate=!0,o(d.imgScroll,361),d.settings.onScrollAct(a,b))},e.onRefreshStop=function(){d.rotINT_stop=!0,d.working=!1,d.txtScroll&&d.txtScroll.html(d.settings.refreshOk),d.viewtips&&d.viewtips.slideUp(200,function(){var a=d.viewport.find("."+d.settings.wrapperClass);a.remove()}),d.viewport.animate({"margin-top":"0px"},200)},h(),this)}}(jQuery);