知识点
- 主要运用到之前封装的动画函数
- 定时器
- 引入我的工具库
运行效果
不断运动
代码
<!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>