我正在尝试制作一个新的Chrome扩展程序,并且我需要该图标自动像带有一系列图像的gif一样进行更改,并永久重复。我的问题是我无法使Javascript循环正常工作。这是我所拥有的:
var min = 1;
var max = 12;
var current = min;
if (current > max)
current = min;
}
var keep_switching_icon = true;
function rotateIcon()
{
if ( keep_switching_icon )
{
chrome.browserAction.setIcon({path:"icon" + current + ".png"});
current++;
window.setTimeout(rotateIcon, 300);
}
}
应该做一些改变:
current > max
应在函数内移动console.clear();
var min = 1;
var max = 12;
var current = min;
var keep_switching_icon = true;
function rotateIcon() {
if (keep_switching_icon) {
//chrome.browserAction.setIcon({path:"icon" + current + ".png"});
console.log(current);
if (current++ > max) {
current = min;
};
window.setTimeout(rotateIcon, 300);
}
}
rotateIcon();
代替console.log(current)
,取消对chrome.browserAction
函数调用的注释并删除第一行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句