码迷,mamicode.com
首页 > Web开发 > 详细

自己做的第一个JS特效

时间:2017-06-17 21:36:38      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:math   定时器   自己   bsp   font   func   osi   document   asc   

星星闪烁效果

<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特效

标签:math   定时器   自己   bsp   font   func   osi   document   asc   

原文地址:http://www.cnblogs.com/zhi-bu/p/7041237.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!