所以,我知道这可能是一个简单的问题需要解决,但无论如何...如何制作变色背景?
我试图让它在那里我可以改变网页的背景颜色,以便象下面这样:
red > yellow > green > blue > purple > pink > brown > red
点击here的网页演示,做我想为我的网页做。
我想我可以在主体元素上使用一些JavaScript:
<html>
<body id="body" bgcolor="#FFFFFF">
<script>
var body = document.getElementById('body'); /* Get
the element with the id of 'body' */
/* I need some javascript to make the 'hex'
variable change accordingly, then call the setColor() with
the parameter as a string for the hex code to change the
background color */
function setColor(hex) {
body.setAttribute("bgcolor", hex); /* Set the
attribute bgcolor to the counter variable */
}
</script>
</body>
</html>
这种方法是有点长写的,但它的作品!谢谢! –
@BenStafford您可以使用Sass函数或Mixin来简化它。 – Roy
我从来没有见过这样的催眠输出在这个网站% - ) – CodingNinja