JS特效——不断在页面跑的星星

知识点

  1. 主要运用到之前封装的动画函数
  2. 定时器
  3. 引入我的工具库

运行效果

不断运动
在这里插入图片描述

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            height: 1000px;
            width: 1000px;
            background-color: black;
            position: relative;
        }
        #star{
            height: 56px;
            width: 56px;
            background:url("star.png");
            position: absolute;
        }
    </style>
</head>
<body>
<div>
    <div id="star"></div>
</div>
</body>
<script src="MyTools.js"></script>
<script>
    window.addEventListener('load',function (ev) {
        setInterval(function () {
            var scale = Math.random() * 2;
            var left = Math.random() * 1000;
            var top = Math.random() * 1000;
            var opacity = Math.random()+0.3;
            var params = {'scale':scale,'left':left,'top':top,'opacity':opacity};
            myTool.slowMoving(myTool.$('star'),params,null);
        },2000);
    },false);
</script>
</html>
发布了214 篇原创文章 · 获赞 112 · 访问量 9380

猜你喜欢

转载自blog.csdn.net/KaiSarH/article/details/103769078