最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Animated Favicon for notification - Stack Overflow

programmeradmin2浏览0评论

I want to notify users for new ining messages when they are browsing other browser tabs.

First I have to set a blinking red bot as a favicon (the problem here is that Google Chrome doesn't support GIF animations as favicon)

$('#favicon').attr('href','_/css/img/favicon.gif');

is there a way to loop through two images one red and one white form 500ms each?

setInterval(function() {
    $('#favicon').attr('href','_/css/img/red.png');
}, 500);

How do I do a loop of 500ms for two icons?

I want to notify users for new ining messages when they are browsing other browser tabs.

First I have to set a blinking red bot as a favicon (the problem here is that Google Chrome doesn't support GIF animations as favicon)

$('#favicon').attr('href','_/css/img/favicon.gif');

is there a way to loop through two images one red and one white form 500ms each?

setInterval(function() {
    $('#favicon').attr('href','_/css/img/red.png');
}, 500);

How do I do a loop of 500ms for two icons?

Share Improve this question asked Mar 19, 2018 at 16:13 medkmedk 9,55918 gold badges61 silver badges82 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

Use a variable and toggle it each time you change:

var red=1; 
setInterval(function() {  
    if (red==1) { 
        red=0;
        $('#favicon').attr('href','_/css/img/white.png');
    } else { 
       red=1;
       $('#favicon').attr('href','_/css/img/red.png');
    }
}, 500);

Plain Javascript it the simplest solution, and such answer was already given.

As an alternative, you can use favicon.js to play a video as the favicon. You could achieve this by converting your existing GIF to a video and then play it with favicon.js. The advantage of this solution is that your animation can be as plex as you want.

发布评论

评论列表(0)

  1. 暂无评论