<!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 () {
<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 () {
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')
})
})
});
}
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和JavaScript实现元素动画的方法,通过控制div元素的位置变化来完成路径动画效果。
1050

被折叠的 条评论
为什么被折叠?



