在一些表单等需要弹窗提醒的时候,每个浏览器都有一个alert(),comfirm()函数能弹出信息,但是浏览器的自带的这种效果样式不统一,而且都固定在页面顶部;
smoke.js轻量级的js插件,他标准化浏览器的alert(), comfirm()效果。完全是由html、css、js编写;
要求:css3支持 兼容性:大部分浏览器,包括ie6(没有css3可视化效果) license:mit 使用方法:本文使用的是click事件,你也可以自定义事件触发类型;
alert confirm prompt quiz signal
样式:
.smoke-base { position: fixed; top: 0; left: 0; bottom: 0; right: 0; visibility: hidden; opacity: 0; } .smoke-base.smoke-visible { opacity: 1; visibility: visible; } .smokebg { position: fixed; top: 0; left: 0; bottom: 0; right: 0; } .smoke-base .dialog { position: absolute; } .dialog-prompt { margin-top: 15px; text-align: center; } .dialog-buttons { margin: 20px 0 5px 0 } .smoke { font-family: menlo, 'andale mono', monospace; text-align: center; font-size: 22px; line-height: 150%; } .dialog-buttons button { display: inline-block; vertical-align: baseline; cursor: pointer; font-family: menlo, 'andale mono', monospace; font-style: normal; text-decoration: none; border: 0; outline: 0; margin: 0 5px; -webkit-background-clip: padding-box; font-size: 13px; line-height: 13px; font-weight: normal; padding: 9px 12px; } .dialog-prompt input { margin: 0; border: 0; font-family: sans-serif; outline: none; font-family: menlo, 'andale mono', monospace; border: 1px solid #aaa; width: 75%; display: inline-block; background-color: transparent; font-size: 16px; padding: 8px; } .smoke-base { background: rgba(0,0,0,.3); filter: progid:dximagetransform.microsoft.gradient(startcolorstr=#90000000,endcolorstr=#900000000); } .smoke-base .dialog { top: 25%; width: 30%; left: 50%; margin-left: -20%; } .smoke-base .dialog-inner { padding: 15px; color:#202020; } .smoke { background-color: rgba(255,255,255,0.95); filter: progid:dximagetransform.microsoft.gradient(startcolorstr=#ffffff,endcolorstr=#ffffff); box-shadow: 0 2px 8px #000; } .dialog-buttons button { background-color: rgba(0,0,0,.85); filter: progid:dximagetransform.microsoft.gradient(startcolorstr=#222222,endcolorstr=#222222); border-radius: 0; color: #fff; } button.cancel { background-color: rgba(0,0,0,.40); filter: progid:dximagetransform.microsoft.gradient(startcolorstr=#444444,endcolorstr=#444444); } .queue{ display:none; }
alert()效果--smoke.alert(string, fn,obj) string--弹出框文字内容,fn--回调函数,obj--{ok:'按钮文字',cancel:'取消按钮文字',classname:'叠加的弹窗框样式名'}
/*alert*/ $('a[rel=demo-alert]').on('click',function(e){ e.preventdefault(); smoke.alert(wouldn't it be funny if animal collective was an actual
collective of actual animals?, function(e){ smoke.signal('no really...it totally would, dude.
i mean, think about it.'); },{ ok: yep, //确定按钮文字 cancel: nope, //取消按钮文字 classname: custom-class //弹出框样式 }); });
confirm效果--smoke.confirm(string,fn,obj)
/*confirm*/ $('a[rel=demo-confirm]').on('click',function(e){ e.preventdefault(); smoke.confirm(slippery breath inside
banjo melted. runny smoky. ,function(e){ if (e){ //确定按钮回调 smoke.signal('perfect. we\'ll be in touch.'); //点击按钮响应lightbox效果,基本上看不见,因为没有设置延迟时间 smoke.signal()会闪一下就消失了。 }else{ //取消按钮回调 smoke.signal('please...me so sorry. you look good in dress, you look better on my floor.'); } }, { reversebuttons: true, //确定和取消按钮哪个在前;true ok按钮在前,false cancel按钮在前 classname: custom-class, ok: agree, //确定文字 cancel: disagree //取消文字 }); });
quiz效果--smoke.quiz(string, fn, obj),多按钮(最多三个)
/*quiz*/ $('a[rel=demo-quiz]').on('click',function(e){ e.preventdefault(); smoke.quiz('which of these things
is the worst thing?', function (e){ if (e == 'disco'){//点击每个按钮的触发的效果 smoke.signal('nope. it\'s funk.'); } if (e == 'reggae'){ smoke.signal('nope. it\'s disco.'); } if (e == 'funk'){ smoke.signal('nope. it\'s reggae.'); } }, { button_1 : disco, //多按钮(最多三个) button_2 : reggae, button_3 : funk, button_cancel: none of them //取消按钮 } ); });
signal,设置弹出框,没有按钮,可以设置弹框消失的延迟时间
/*signal*/ $('a[rel=demo-signal]').on('click',function(e){ e.preventdefault(); smoke.signal('congratulations! you have just one a free ipod touch!', function(){}, {duration: 5000, classname: custom-class});//duration:5000设置延迟时间为5000毫秒 });
prompt,带有输出框的alert效果
/*prompt*/ $('a[rel=demo-prompt]').on('click',function(e){ e.preventdefault(); o.prompt_demo(1); });var o={ prompt_demo: function(ver){ var q = 'what\'s in the bag?';//设置提示文字,这个是用来遵循文本框的内容约束规则。文本框如果是必填的话就会需要,在用户移除文本框的时候就会触发提示文字。 if (ver == 2){ q = 'no no, you have to answer.
what\'s in the bag?'; } smoke.prompt(q, function(e){ if (e){//ok按钮的效果 smoke.signal('you have no idea how badly
i need a bag of '+e+'.
give it to me. right now.
'); }else{//cancel按钮效果 o.prompt_demo(2); } }, { reversebuttons: true,//翻转按钮顺序 value: 'hammers', //文本框里的默认内容 ok: 'have a look', //确定按钮文字 cancel: 'none of your business' //取消按钮文字 });}}
鼠标移除文本框后或单击cancel按钮