改变网页背景色的一种思路

随便写写啦,其实太简单啦,就当玩玩配色:
http://codepen.io/tianzi77/pen/GJPRYE

结构html

   <div class="bg">
    <div id="yellow"></div>
    <div id="red"></div>
    <div id="green"></div>
    <div id="blue"></div>
    <div id="lanse"></div>
    <div id="orange"></div>
    <div id="pink"></div>
    </div>

css样式:

        .bg{
            border: 2px solid #abcdef;
            border-radius: 10px;
            background:-webkit-linear-gradient(top left,pink,#fff);
            position: fixed;
            left: 40%;
        }
        #yellow {
            width: 20px;
            height: 20px;
            background: #cff9f5;
            border-radius: 50%;
        }

        #red {
            width: 20px;
            height: 20px;
            background: #f9a3c9;
            border-radius: 50%;
        }

        #green {
            width: 20px;
            height: 20px;
            background: #f5f89a;
            border-radius: 50%;
        }

        #blue {
            width: 20px;
            height: 20px;
            background: #86d1fc;
            border-radius: 50%;
        }
        #lanse{
            width: 20px;
            height: 20px;
            background: #abcdef;
            border-radius: 50%;
        }
        #orange{
            width: 20px;
            height: 20px;
            background: orange;
            border-radius: 50%;
        }
        #pink{
            width: 20px;
            height: 20px;
            background: pink;
            border-radius: 50%;
        }
        div {
            display: inline-block;
            margin: 10px;
            cursor: pointer;
        }

js控制改变颜色:

        window.onload = function () {
            var Y = document.getElementById('yellow');
            var R = document.getElementById('red');
            var G = document.getElementById('green');
            var B = document.getElementById('blue');
            var L=document.getElementById('lanse');
            var o=document.getElementById('orange');
            var P=document.getElementById('pink');
            Y.onclick = function () {
                document.body.style.backgroundColor = '#cff9f5';
            }
            R.onclick = function () {
                document.body.style.backgroundColor = '#f9a3c9';
            }
            G.onclick = function () {
                document.body.style.backgroundColor = '#f5f89a';
            }
            B.onclick = function () {
                document.body.style.backgroundColor = '#86d1fc';
            }
            L.onclick = function () {
                document.body.style.backgroundColor = '#abcdef';
            }
            o.onclick = function () {
                document.body.style.backgroundColor = 'orange';
            }
            P.onclick = function () {
                document.body.style.backgroundColor = 'pink';
            }
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值