我想知道我是否能得到帮助,使我的网站改变为一个随机配色方案(前)。在刷新页面时,用红色和黄色的悬空替换蓝色的背景)。这是代码(http://jsbin.com/yudiwaza/1/edit?html,css,js,output)。我一直在谷歌,但似乎找不到解决方案,我找到了与我的网站。任何帮助都是非常感谢的!
发布于 2014-05-20 04:42:00
不要随意使用颜色,它们看起来很难看--自己定义颜色。
最好的方法是在body标记上应用一个随机类,并使用CSS来更改颜色。例如,我正在更改演示中的背景色,但您可以更改任何东西,控制您的整个布局样式。
JS:
$(function(){
var themeClassName = "theme_"+Math.floor((Math.random() * 10) + 1);
$('body').addClass(themeClassName);
});Css:
.theme_1{
background: #f00;
}
.theme_2{
background: #0f0;
}
.theme_3{
background: #00f;
}
.theme_4{
background: #000;
}
.theme_ .... // till 10 different classes如果您想要的主题数量小于或超过10个,则更改此值:
(Math.random() * 10 <--This value from the above codehttps://stackoverflow.com/questions/23750948
复制相似问题