forked from Correlife/SpriteLoading.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpriteLoading.min.js
1 lines (1 loc) · 2.82 KB
/
SpriteLoading.min.js
1
var SpriteLoading=function(t,e){e=e||{};var i=$.extend({width:60,height:60,delay:40,frames:{start:1,loop_start:12,loop_end:35,out_end:45},backdrop:!1,text:!1,bar:!1,theme:"light",sprite_url:"https://raw.githubusercontent.com/Correlife/SpriteLoading.js/master/loading.png",sprite_url_dark:"https://raw.githubusercontent.com/Correlife/SpriteLoading.js/master/loading-dark.png"},e),a=i.frames.start,r=this;if(this.set_finish=!1,this.finish_callback=function(){},i.backdrop)var s=$('<div class="sprite-loading-backdrop"></div>').appendTo(t).css({opacity:.5,backgroundColor:"dark"===i.theme?"#fff":"#000",width:"100%",height:"100%",position:"absolute",top:0}).hide().fadeIn(200);i.text!==!1&&i.text.length>0&&(this.text_el=$('<div class="sprite-loading-text"></div>').appendTo(t).css({color:"dark"===i.theme?"#000":"#fff",width:"100%",height:"auto",position:"absolute",top:"50%",transform:"translateY(-50%)","-webkit-transform":"translateY(-50%)","-ms-transform":"translateY(-50%)","text-align":"center","margin-top":i.height+"px"}).text(i.text).hide().fadeIn(200)),i.bar!==!1&&(this.bar_el=$('<div class="sprite-loading-bar"></div>').appendTo(t).css({width:"200px",height:"5px",position:"absolute",backgroundColor:"dark"===i.theme?"#727690":"#D3D6DD",padding:"0",top:"50%",transform:"translateY(-50%)","-webkit-transform":"translateY(-50%)","-ms-transform":"translateY(-50%)","margin-top":i.height-15+"px",left:"50%","margin-left":"-100px"}).hide().fadeIn(200),this.bar_progress_el=$('<div class="sprite-loading-bar-progress"></div>').appendTo(this.bar_el).css({width:"0%","-webkit-transition":"width 0.2s ease-out","-moz-transition":"width 0.2s ease-out","-o-transition":"width 0.2s ease-out",transition:"width 0.2s ease-out",height:"100%",backgroundColor:"#F8B533"}).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"===i.theme?i.sprite_url_dark:i.sprite_url)+"')",width:i.width+"px",height:i.height+"px",position:"absolute","background-position-x":0,"background-position-y":"-"+i.height+"px",top:"50%",transform:"translateY(-50%)","-webkit-transform":"translateY(-50%)","-ms-transform":"translateY(-50%)",left:"50%","margin-left":"-"+i.width/2+"px"});var n=window.setInterval(function(){a+=1,a>i.frames.loop_end&&(r.set_finish===!0?a>i.frames.out_end&&(clearInterval(n),i.backdrop&&s.fadeOut(200,function(){$(this).remove()}),i.text&&r.text_el.remove(),i.bar&&r.bar_el.remove(),o.remove(),r.finish_callback()):a=i.frames.loop_start),o.css("background-position-y",-i.height*(a-1))},i.delay)};SpriteLoading.prototype.finish=function(t){this.set_finish=!0,this.finish_callback=t||function(){}},SpriteLoading.prototype.updateText=function(t){this.text_el.text(t)},SpriteLoading.prototype.updateBar=function(t){this.bar_progress_el.css({width:t+"%"})};