-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpriteLoading.min.js
1 lines (1 loc) · 1.37 KB
/
SpriteLoading.min.js
1
var SpriteLoading=function(t,i){i=i||{};var a=$.extend({width:60,height:60,delay:40,frames:{start:1,loop_start:12,loop_end:35,out_end:45},backdrop:!1,theme:"light",sprite_url:"/img/loading.png",sprite_url_dark:"/img/loading-dark.png"},i),s=a.frames.start,e=this;if(this.set_finish=!1,this.finish_callback=!1,a.backdrop)var r=$('<div class="sprite-loading-backdrop"></div>').appendTo(t).css({opacity:.5,backgroundColor:"dark"===a.theme?"#fff":"#000",width:"100%",height:"100%",position:"absolute",top:0}).hide().fadeIn(200);var o=$('<div class="sprite-loading"></div>').appendTo(t);"static"===o.parent().css("position")&&o.parent().css({position:"relative"}),o.css({background:"url('"+("dark"===a.theme?a.sprite_url_dark:a.sprite_url)+"')",width:a.width+"px",height:a.height+"px",position:"absolute","background-position-x":0,"background-position-y":"-"+a.height+"px",top:"50%",transform:"translateY(-50%)","-webkit-transform":"translateY(-50%)","-ms-transform":"translateY(-50%)",left:"50%","margin-left":"-"+a.width/2+"px"});var n=window.setInterval(function(){s+=1,s>a.frames.loop_end&&(e.set_finish===!0?s>a.frames.out_end&&(clearInterval(n),a.backdrop&&r.fadeOut(200,function(){$(this).remove()}),o.remove(),e.finish_callback()):s=a.frames.loop_start),o.css("background-position-y",-a.height*(s-1))},a.delay)};SpriteLoading.prototype.finish=function(t){this.set_finish=!0,this.finish_callback=t};