我最终为一组颜色生成了类,并使用 javascript 定期随机更改类。
// css.styl
colors = 0 30 60 90 120 150 180 210 240 270 300 330
for hue, index in colors
color = hsl(hue, 100%, 75%)
.bodyColor{index}
color: lighten(color, 55%) !important
//background-color: darken(color, 97%) !important
.borderColor{index}
border-color: darken(color, 65%) !important
a.linkColor{index}, a.linkColor{index}:visited
color: lighten(color, 85%)
.containerColor{index}
background-color: color !important
a.buttonColor{index}
color: darken(color, 75%) !important
background-color: lighten(color, 25%)
a.buttonColor{index}:hover
background-color: darken(color, 50%)
color: lighten(color, 85%) !important
// animateColor.js
(function ($) {
$(document).bind('initialize', function (e) {
if (!e.firstLoad) return;
var colorIndex = 3,
delay = 10,
items = [
{ element: 'body', cssClass: 'bodyColor' },
{ element: '#banner', cssClass: 'borderColor' },
{ element: 'a', cssClass: 'linkColor' },
{ element: '.translucentFrame', cssClass: 'containerColor' },
{ element: 'a.button', cssClass: 'buttonColor' }
];
$(document).data('colorItems', items);
(function changeColors() {
items.forEach(function (item) {
$(item.element).removeClass(item.cssClass + colorIndex);
});
colorIndex = Math.floor(Math.random()*11);
$(document).data('colorIndex', colorIndex);
items.forEach(function (item) {
$(item.element).addClass(item.cssClass + colorIndex);
});
setTimeout(changeColors, delay * 1000);
})();
});
})(jQuery);