首页 > 代码库 > 自己做的第一个JS特效

自己做的第一个JS特效

星星闪烁效果

<body bgcolor="black">
</body>
    <script type="text/JavaScript">
    
    //循环遍历div
    for (var i = 0; i < 50; i++) {
        document.write("<div name=‘shuzi‘ style=‘font-size: 20px;color: yellow;position: absolute;top:0px;‘>☆</div>")    
    }

    //获取div元素
    topa=1;
    topb=document.getElementsByName(‘shuzi‘);
    topc=document.getElementsByName(‘ss‘);

    //设定整数随机
    //n 最小随机数
    //m 最大随机数
    function rd(n,m){
        var c=m-n+1;
        return Math.floor(Math.random()*c+n);
    }

    //定时器
    setInterval(function(){
        topa++;
        for (var i = 0; i < topb.length; i++) {
            shu=Math.random();
            shu=shu.toFixed(2);
            topb[i].style.top=Math.random()*1200+"px";
            topb[i].style.left=Math.random()*1000+"px";
            topb[i].style.color="rgba("+rd(0,255)+","+rd(0,255)+","+rd(0,255)+","+shu+")";    
        }    
    },200);
    </script>
</html>

自己做的第一个JS特效