html结合JavaScript制作的霓虹灯

这里写代码片<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>霓虹灯</title>
    <style>
        div{
            border: 1px solid #000000;/*设置一个黑色的边框 边框的像素为1*/
            position: absolute;/*定位*/
            margin: auto;/*设置浏览器的边距*/
            left: 0;/*左边的边距设置为0*/
            top: 0;/*上边的边距设置为0*/
            right: 0;/*右边的边距设置为0*/
            bottom: 0;/*下边的边距设置为0*/
        }
        /*调用ID边框div01,设置最外边的边框长和高为600像素,
        后面的每一个边框是上面的边框减掉50像素*/
        #div01{
            width: 600px;
            height: 600px;
        }
        #div02{
            width: 550px;
            height: 550px;
        }
        #div03{
            width: 500px;
            height: 500px;
        }
        #div04{
            width: 450px;
            height: 450px;
        }
        #div05{
            width: 400px;
            height: 400px;
        }
        #div06{
            width: 350px;
            height: 350px;
        }
        #div07{
            width: 300px;
            height: 300px;
        }
        #div08{
            width: 250px;
            height: 250px;
        }
        #div09{
            width: 200px;
            height: 200px;
        }
        #div10{
            width: 150px;
            height: 150px;
        }
        #div11{
            width: 100px;
            height: 100px;
        }
    </style>
</head>
<body>

<div id="div01"><!--设置边框的ID为div01-->
    <div id="div02"><!--设置边框的ID为div02-->
        <div id="div03"><!--设置边框的ID为div03-->
            <div id="div04">
                <div id="div05">
                    <div id="div06">
                        <div id="div07">
                            <div id="div08">
                                <div id="div09">
                                    <div id="div10">
                                        <div id="div11">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--JavaScript(Java脚本)代码的实现-->
<script>
    //定义数组实现(id的数组,颜色的数组)
    ## 第一种方式单色跑一轮换色 ##

    var arrayDivId=["div01","div02","div03","div04","div05","div06","div07","div08","div09","div10","div11"];
    var arrayColor=["#00EE00","#050505","#0000AA","#1C86EE","#4B0082","#54FF9F","#66CDAA","#F08080","#FAFAFA","#FFFF00","#FF3030","#000000"];
    var i=11;
    var random=Math.floor(Math.random()*arrayColor.length);
    function fun() {
        i--;
        if(i<1){
            i=11;
            random=Math.floor(Math.random()*arrayColor.length);
        }
        document.getElementById("div0"+i).style.backgroundColor=arrayColor[random];

    }
     setInterval("fun()",10);

    //定义函数
 ## 第二种方式多种颜色一起 ##
//第二种方式    /* function mfun() {
        //混合搭配,对于数组产生随机索引,两者的索引值,两次的效果不容易出现相同的情况
        var indexDivId=Math.floor(Math.random()*(arrayDivId.length));
        var indexColor=Math.floor(Math.random()*(arrayColor.length));
        //设置背景颜色,给div设置背景颜色,改变CSS样式, 可以使用JavaScript代码完成
        var xdiv=document.getElementById(arrayDivId[indexDivId]);
        xdiv.style.backgroundColor=arrayColor[indexColor];
    }
    //开启定时器,设置时间的毫秒值
    setInterval("mfun()",50);*/



</script>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值