注:本分非原创;信息来源 oschinajavascript
受权协议:MITjava
开发语言:JavaScriptgit
操做系统:跨平台github
软件做者:同一种调调chrome
iNotify.js 详细介绍npm
JS 实现浏览器的 title 闪烁、滚动、声音提示、chrome、Firefox、Safari等系统通知。数组
1 $ npm install title-notify --save-dev 2 $ bower install inotify --save-dev
1 # 下载依赖工具 2 $ npm install 3 # 压缩inotify 4 $ npm build
effect: flash | scroll | favicon浏览器
1 var iNotify = new iNotify().init() 2 //推荐下面写法 3 var iNotify = new iNotify({ 4 message: '有消息了。',//标题 5 effect: 'flash', // flash | scroll 闪烁仍是滚动 6 openurl:"http://www.bing.com", // 点击弹窗打开链接地址 7 onclick:function(){ //点击弹出的窗之行事件 8 console.log("---") 9 }, 10 //可选播放声音 11 audio:{ 12 //能够使用数组传多种格式的声音文件 13 file: ['msg.mp4','msg.mp3','msg.wav'] 14 //下面也是能够的哦 15 //file: 'msg.mp4' 16 }, 17 //标题闪烁,或者滚动速度 18 interval: 1000, 19 //可选,默认绿底白字的 Favicon 20 updateFavicon:{ 21 // favicon 字体颜色 22 textColor: "#fff", 23 //背景颜色,设置背景颜色透明,将值设置为“transparent” 24 backgroundColor: "#2F9A00" 25 }, 26 //可选chrome浏览器通知,默认不填写就是下面的内容 27 notification:{ 28 title:"通知!",//设置标题 29 icon:"",//设置图标 icon 默认为 Favicon 30 body:'您来了一条新消息'//设置消息内容 31 } 32 })
判断浏览器弹框通知是否被阻止。工具
1 iNotify.isPermission()
播放声音oop
1 iNotify.player()
自动播放声音
1 iNotify.loopPlay()
中止播放声音
1 iNotify.stopPlay()
设置播放声音URL
1 iNotify.setURL('msg.mp3')// 设置一个 2 iNotify.setURL(['msg.mp3','msg.ogg','msg.mp4']) // 设置多个
1 最新的版本默认不播放标题闪烁动画,初始化以后须要调用 setTitle(true) 方法才播放标题动画。
设置标题,
1 iNotify.setTitle(true)//播放动画 2 iNotify.setTitle('新标题')//闪烁新标题 3 iNotify.setTitle()//清除闪烁 显示原来的标题
设置时间间隔
1 iNotify.setInterval(2000)
添加计数器
1 iNotify.addTimer()
清除计数器
1 2 iNotify.clearTimer() 3
设置icon 显示数字
1 2 iNotify.setFavicon(10) 3
1 清除数字显示原来的icon 2 iNotify.faviconClear() 3
1 弹出chrome通知,不传参数为预设值... 2 iNotify.notify(); 3 iNotify.notify({ 4 title:"新通知", 5 body:"打雷啦,下雨啦...", 6 openurl:"http://www.bing.com", 7 onclick:function(){ 8 console.log("---") 9 } 10 }); 11
1 iNotify.init().title; 获取标题
1 new iNotify({ 2 effect: 'flash', 3 interval: 500 4 }) 5 6 上面的例子跟下面的是同样的 7 new iNotify().init({ 8 effect: 'flash', 9 interval: 500 10 }); 11
1 function iconNotify(num){ 2 if(!notify) { 3 var notify = new iNotify().init({ 4 effect: 'flash', 5 interval: 500 6 }); 7 } 8 if(num===0){ 9 notify.faviconClear() 10 notify.setTitle(); 11 }else if(num<100){ 12 notify.setFavicon(num) 13 notify.setTitle("有新消息!"); 14 }else if(num>99){ 15 notify.setFavicon('..') 16 notify.setTitle("有新消息!"); 17 } 18 }
1 var notify = new iNotify().init({ 2 effect: 'flash', 3 interval: 500 4 }); 5 notify.setFavicon("1")
1 var iN = new iNotify().init({ 2 effect: 'flash', 3 interval: 500, 4 message:"有消息拉!", 5 updateFavicon:{//可选,默认绿底白字 6 textColor: "#fff",// favicon 字体颜色 7 backgroundColor: "#2F9A00" //背景颜色 8 } 9 }).setFavicon(10);
1 var iN = new iNotify().init().setFavicon(5);
1 var iN = new iNotify().init({ 2 effect: 'flash', 3 interval: 500, 4 message:"有消息拉!", 5 audio:{ 6 file: 'msg.mp4' 7 } 8 }).setFavicon(10).player();
1 var iN = new iNotify().init({ 2 effect: 'flash', 3 interval: 500, 4 message:"有消息拉!", 5 audio:{ 6 file: 'msg.mp4'//能够使用数组传多种格式的声音文件 7 }, 8 notification:{ 9 title:"通知!", 10 icon:"", 11 body:'您来了一条新消息' 12 } 13 }).setFavicon(10).player(); 14 15 //弹出chrome通知,不传参数为预设值... 16 iN.notify(); 17 18 iN.notify({ 19 title:"新通知", 20 body:"打雷啦,下雨啦..." 21 });
1 var iN = new iNotify({ 2 effect: 'flash', 3 interval: 500, 4 message:"有消息拉!", 5 audio:{ 6 file: ['msg.mp4','msg.mp3','msg.wav'] 7 }, 8 notification:{ 9 title:"通知!", 10 body:'您来了一条新消息' 11 } 12 }) 13 14 15 iN.setFavicon(10).player(); 16 17 var n = new iNotify() 18 n.init({ 19 effect: 'flash', 20 interval: 500, 21 message:"有消息拉!", 22 audio:{ 23 file: ['openSub.mp4','openSub.mp3','openSub.wav'] 24 }, 25 notification:{ 26 title:"通知!", 27 icon:"", 28 body:'您来了一个客户' 29 } 30 }) 31 32 n.setFavicon(10).player();
JS 实现浏览器的 title 闪烁、滚动、声音提示、通知,没有依赖。https://github.com/jaywcjlove/iNotify
|