1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | /** * 封装flavr,方便使用 */ var Flavr = function () { //动画数组 var animates = [ "tada" , "swing" , "shake" , "rubberBand" , "bounce" , "pulse" ]; //获取随机动画 function getAnimate() { return animates[Math.floor(Math.random() * animates.length)]; } var fr = { /** * 弹窗信息 * @param {String} 信息内容 */ alert: function (msg) { new $.flavr({ buttons: { OK: { text: 'OK' , style: 'default' , addClass: null , action: null } }, animateEntrance: getAnimate(), content: msg }); }, /** * 提示信息 * @param {String} 信息内容 */ msg: function (msg) { new $.flavr({ modal: false , autoclose: true , timeout: 2000, buttons: {}, animateEntrance: getAnimate(), content: msg }); }, /** * 确认信息 * @param {String} 信息内容 * @param {Function} 确认回调函数 * @param {Function} 取消回调函数 */ confirm: function (msg, okBack, cancelBack) { new $.flavr({ dialog: 'confirm' , buttons: { OK: { text: '确认' , style: 'danger' , addClass: null , action: okBack }, CANCEL: { text: '取消' , addClass: null , action: cancelBack } }, animateEntrance: getAnimate(), content: msg }); } } return fr; } var flavr = new Flavr(); flavr.alert( "Flavr Alert" ); flavr.msg( "Flavr Msg" ); flavr.confirm( "确定删除吗?" , function () { flavr.msg( "删除成功" ); }); |
把按钮内容变成中文实例,我是参考多个按钮demo改出来的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | new $.flavr({ content: 'How old are you?' , dialog: 'prompt' , prompt: { placeholder: 'Enter something' }, buttons: { danger: { text: '确定' , style: 'danger' , action: function () { alert( 'Mission failed!' ); return false ; } }, cancel: { text: '取消' , style: 'default' } }, }); |