(function () { var tpl = '
{svg}
', loading = '._loading_', LOADING_SVG = [ '', '', ]; /** * Loading * * @param opts * @constructor */ function Loader(opts) { var defStyle = 'position:absolute;left:10px;right:10px;', content, $container; opts = $.extend({ container: '#pjax-container', z_index: 100, width: '50px', color: '#84bdea', bg: '#fff', style: '', svg: LOADING_SVG[0] }, opts); $container = opts.container; $container = $container == 'object' ? $container : $($container); content = $( tpl .replace('{svg}', opts.svg) .replace('{color}', opts.color) .replace('{color}', opts.color) .replace('{width}', opts.width) .replace('{style}', defStyle + 'background:' + opts.bg + ';' + 'z-index:' + opts.z_index + ';' + opts.style) ); content.appendTo($container); this.remove = function () { $container.find(loading).remove(); }; } Loader.destroyAll = function () { $(loading).remove(); }; LA.Loader = Loader; // 全屏居中loading LA.loading = function (opts) { if (opts === false) { // 关闭loading return setTimeout(LA.Loader.destroyAll, 70); } // 配置参数 opts = $.extend({ color: '#62abe4', z_index: 999991014, width: '58px', shade: 'rgba(255, 255, 255, 0.02)', top: 200, svg: LOADING_SVG[1], }, opts); var win = $(window), // 容器 $container = $('
'), // 遮罩层直接沿用layer shadow = $('
'); $container.appendTo('body'); if (opts.shade) { shadow.appendTo('body'); } function resize() { $container.css({ left: (win.width() - 300)/2, top: (win.height() - opts.top)/2 }); } // 自适应窗口大小 win.on('resize', resize); resize(); $container.loading(opts); }; $.fn.loading = function (opt) { if (opt === false) { return $(this).find(loading).remove(); } opt = opt || {}; opt.container = $(this); return new Loader(opt); }; })();