ドキュメントの本文の背景色としてアニメーション化する必要がある色のリストがあります。
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);
});
質問
(前述のコードのチャンクの最適化)パフォーマンスの最適化の観点から、このアニメーションを実行するためのより良い方法はありますか?
(vs. jQuery) jQueryの対応物はより効率的でエレガントでしょうか?