简体   繁体   English

菜单栏通知徽章更新问题

[英]Menu bar notification badge update issue

I have a menu bar with notification bubble badge (CSS3), and a php script to retrive the new messages count from mysql database (messenger inbox system). 我有一个带有通知气泡徽章(CSS3)的菜单栏,以及一个php脚本,用于从mysql数据库(messenger收件箱系统)中检索新消息数。 I want to update the value of the notification badge every second with the number of unread messages from the script or hide the container completely if the script result is 0 (no new messages). 我想用脚本中未读消息的数量每秒更新通知标志的值,或者如果脚本结果为0(没有新消息),则完全隐藏容器。

I finally figured it out after 48 hours awake! 终于醒了48小时,我终于弄明白了!

setTimeout('pullNewMessageCount()', 200);
function pullNewMessageCount() {
var url = 'models/bubble.php';
$.ajax({
url: url,
dataType: 'html',
type: 'POST',
success: function(latestCount) {
 setTimeout('pullNewMessageCount()', 200);
 $('#bub').html(latestCount);
 if (latestCount > 0)
 {
   $('#bub').removeClass('hidden').addClass('bubble').addClass('animating');
 } else if ((latestCount = $('#bub').html()) && (latestCount > 0)) {
   $('#bub').removeClass('animating');
 } else if ((latestCount = '0') || (!latestCount)) {
   $('#bub').removeClass('bubble').addClass('hidden');
 } else {
   $('#bub').removeClass('bubble').addClass('hidden');
 }
},
error: function(jqXHR, textStatus, errorThrown) {
}
});
}

and finally a working facebook-like notification bubble system! 最后是一个类似Facebook的通知气泡系统!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM