/* 时代java - https://nowjava.com */ var zindex = 1000; var jqueryalert = function(opts){ // 设置默认参数 var opt = { 'style' : 'wap', //移动端和pc端 'title' : '', //标题 'content' : '', //内容 'contenttextalign' : 'center', //内容对齐方式 'width' : 'auto', //宽度 'height' : 'auto', //高度 'minwidth' : '0', //最小宽度 "classname" : '', //添加类名 'position' : 'fixed', //定位方式 'animatetype' : 'scale', 'modal' : false, //是否存在蒙层 'ismodalclose' : false, //点击蒙层是否关闭 'bodyscroll' : false, //是否关闭body的滚动条 'closetime' : 3000, //当没有按钮时关闭时间 "buttons" : {}, //按钮对象 } // 参数合并 var option = $.extend({},opt,opts); var dialog = { } dialog.time = 450;//动画关闭时间 dialog.init = function(){ dialog.framework(); } // 事件处理 var ishavetouch = "ontouchend" in document ? true : false; if(ishavetouch){ dialog.event = 'touchstart'; }else{ dialog.event = 'click'; } var $modal = $("
"+ key +"
"); if(option.style != 'pc'){ $button.css({ 'width' : math.floor(($container[0].clientwidth) / dialog.buttonslength), }) } //绑定点击后的事件 $button.bind(dialog.event,option.buttons[key]); $buttonbox.append($button); } if(dialog.buttonslength > 0){ $container.append($buttonbox); $content.css('padding-bottom','46px'); } if(option.title != ''){ $content.css('padding-top','42px'); } if(dialog.buttonslength <= 0 && option.title == ''){ $container.addclass('alert-container-black'); } // 设置定位 $container.css({ 'margin-left' : -parseint($container.css('width'))/2, 'margin-top' : -parseint($container.css('height'))/2, }); if(option.animatetype == 'scale'){ $container.addclass('bouncein'); } if(option.animatetype == 'linear'){ $container.addclass('lineartop'); } isselfclose(); }; // 判断是否满足自动关闭的条件 function isselfclose(){ if(dialog.buttonslength <= 0 && option.style != 'pc'){ settimeout(function(){ $container.fadeout(300); $modal.fadeout(300); option.bodyscroll && $('body').css('overflow','auto'); },option.closetime) } } dialog.toggleanimate = function(){ if(option.animatetype == 'scale'){ return $container.removeclass('bouncein').addclass('bounceout'); }else if(option.animatetype == 'linear'){ return $container.removeclass('lineartop').addclass('linearbottom'); }else{ return $container; } } dialog.close = function(){ dialog.toggleanimate().fadeout(dialog.time); $modal.fadeout(dialog.time); option.bodyscroll && $('body').css('overflow','auto'); }; option.style == 'pc' && $closebtn.bind(dialog.event,dialog.close); option.ismodalclose && $modal.bind(dialog.event,dialog.close); dialog.destroy = function(){ dialog.toggleanimate().fadeout(dialog.time); settimeout(function(){ $container.remove(); $modal.remove(); option.bodyscroll && $('body').css('overflow','auto'); },dialog.time) } dialog.show = function(){ $modal.css('z-index',zindex); ++zindex; $container.css({ 'z-index' : zindex, }) if(option.animatetype == 'scale'){ $container.fadein().removeclass('bounceout').addclass('bouncein'); }else if(option.animatetype == 'linear'){ $container.fadein().removeclass('linearbottom').addclass('lineartop'); }else{ $container.fadein() } if(option.position == 'absolute'){ $container.css({ 'top' : $(window).height()/2 + $(window).scrolltop(), }) } $modal.fadein(); option.bodyscroll && option.modal && $('body').css('overflow','hidden'); isselfclose(); } dialog.init(); return dialog; }