我有一个颜色列表,需要将其作为文档正文背景颜色进行动画处理。
var bgs = [
"BlanchedAlmond",
"Blue",
"BlueViolet",
"Brown",
"BurlyWood",
"CadetBlue",
"Chartreuse",
"Chocolate",
"Coral",
"CornflowerBlue",
"Cornsilk",
"Crimson",
"Cyan",
"DarkBlue",
"DarkCyan"
];
现在,使用mootools 的 colorToHex() 自定义函数,我最终得到以下代码:
window.addEvent('domready', function() {
var current;
(function() {
selected = ~~(Math.random() * bgs.length);
// is it a right way to avoid the repetition?
current = (selected == current) ? ((bgs.length-1) % (selected+1)) : selected;
// -1 is to avoid the edge case,
// +1 is to avoid the NaN in case select is 0
$(document.body).set('tween', {duration: '1500'})
.tween("background-color",bgs[current].colorToHex());
}).periodical(1000);
});
问题
(上述代码块的优化)从性能优化的角度来看,有没有更好的方法来执行这个动画?
(与 jQuery 相比) jQuery 对应物会更高效、更优雅吗?