Chrome Progress Rich 通知状态不会向上移动
Chrome Progress Rich Notification Status won't Move Up
我尝试制作 Chrome 进度丰富通知,但状态栏不会移动。
我认为这段代码可以工作。状态栏将每 40 毫秒上升 1%。通知在 4 秒后消失(恰好也是 100%)。我认为我的 setInterval
有问题
var notifyStatus = function(title, message) {
var k = 0;
chrome.notifications.create('', {
'type': 'progress',
'iconUrl': 'images/icon128.png',
'title': title,
'message': message || '',
'progress': setInterval(function() {
if (k>100) {k;}
else {k++;}
},40)
}, function(nid) {
// Automatically close the notification in 4 seconds.
window.setTimeout(function() {
chrome.notifications.clear(nid);
}, 4000);
});
};
目前您正在将 progress
分配给任何值 setInterval returns 仅一次。
您需要每 40 毫秒用新的进度值更新一次通知,使用 chrome.notifications.update:
var notifyStatus = function(title, message, timeout) {
chrome.notifications.create({
type: 'progress',
iconUrl: 'images/icon128.png',
title: title,
message: message || '',
progress: 0
}, function(id) {
// Automatically close the notification in 4 seconds by default
var progress = 0;
var interval = setInterval(function() {
if (++progress <= 100) {
chrome.notifications.update(id, {progress: progress}, function(updated) {
if (!updated) {
// the notification was closed
clearInterval(interval);
}
});
} else {
chrome.notifications.clear(id);
clearInterval(interval);
}
}, (timeout || 4000) / 100);
});
};
我尝试制作 Chrome 进度丰富通知,但状态栏不会移动。
我认为这段代码可以工作。状态栏将每 40 毫秒上升 1%。通知在 4 秒后消失(恰好也是 100%)。我认为我的 setInterval
var notifyStatus = function(title, message) {
var k = 0;
chrome.notifications.create('', {
'type': 'progress',
'iconUrl': 'images/icon128.png',
'title': title,
'message': message || '',
'progress': setInterval(function() {
if (k>100) {k;}
else {k++;}
},40)
}, function(nid) {
// Automatically close the notification in 4 seconds.
window.setTimeout(function() {
chrome.notifications.clear(nid);
}, 4000);
});
};
目前您正在将 progress
分配给任何值 setInterval returns 仅一次。
您需要每 40 毫秒用新的进度值更新一次通知,使用 chrome.notifications.update:
var notifyStatus = function(title, message, timeout) {
chrome.notifications.create({
type: 'progress',
iconUrl: 'images/icon128.png',
title: title,
message: message || '',
progress: 0
}, function(id) {
// Automatically close the notification in 4 seconds by default
var progress = 0;
var interval = setInterval(function() {
if (++progress <= 100) {
chrome.notifications.update(id, {progress: progress}, function(updated) {
if (!updated) {
// the notification was closed
clearInterval(interval);
}
});
} else {
chrome.notifications.clear(id);
clearInterval(interval);
}
}, (timeout || 4000) / 100);
});
};