转圈圈动画animation
2016-01-21 22:20
405 查看
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<style>
*{
margin:0;
padding:0;
}
#circle{
background-color:coral;
height:100px;
width:100px;
position:relative;
}
</style>
<script>
window.onload = function () {
for (var i = 0; i < 20; i++) {
var Odiv = document.getElementById('circle');
// Odiv.onmouseover = function () {
StartMove(window.screen.availWidth - 100, 'offsetLeft', 'left', function () {
StartMove(window.screen.availHeight - 170, 'offsetTop', 'top', function () {
StartMove(0, 'offsetLeft', 'left', function () {
StartMove(0, 'offsetTop', 'top')
})
})
});
}
}
// }
var timer = null;
function StartMove(itarget, key, direction, fn) {
clearInterval(timer);
var Odiv = document.getElementById('circle');
timer = setInterval(function () {
var speed = (itarget - Odiv[key]) / 5;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (Odiv[key] == itarget) {
clearInterval(timer);
if (fn) {
fn();
}
}
else {
Odiv.style[direction] = Odiv[key] + speed + 'px';
}
}, 30)
}
</script>
</head>
<body>
<div id="circle"></div>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<style>
*{
margin:0;
padding:0;
}
#circle{
background-color:coral;
height:100px;
width:100px;
position:relative;
}
</style>
<script>
window.onload = function () {
for (var i = 0; i < 20; i++) {
var Odiv = document.getElementById('circle');
// Odiv.onmouseover = function () {
StartMove(window.screen.availWidth - 100, 'offsetLeft', 'left', function () {
StartMove(window.screen.availHeight - 170, 'offsetTop', 'top', function () {
StartMove(0, 'offsetLeft', 'left', function () {
StartMove(0, 'offsetTop', 'top')
})
})
});
}
}
// }
var timer = null;
function StartMove(itarget, key, direction, fn) {
clearInterval(timer);
var Odiv = document.getElementById('circle');
timer = setInterval(function () {
var speed = (itarget - Odiv[key]) / 5;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if (Odiv[key] == itarget) {
clearInterval(timer);
if (fn) {
fn();
}
}
else {
Odiv.style[direction] = Odiv[key] + speed + 'px';
}
}, 30)
}
</script>
</head>
<body>
<div id="circle"></div>
</body>
</html>
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- Extjs4.0 最新最全视频教程
- Javascript中toFixed方法的改进
- Web布局连载——两栏固定布局(五)
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 5个常见可用性错误和解决方案
- [div+css]晒晒最新制作专题推广页模板
- 在Windows 8.1的IE 11中屏蔽双击放大功能
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因