87,990
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<style type="text/css">
#div1{width:0px; height:0px; background:#CCC; position:absolute; left:0px; top:0px;}
#div2{width:0px; height:0px; background:#000; position:absolute; left:500px; top:500px;}
#div3{width:0px; height:0px; background:#ff0; position:absolute; left:0px; top:0px;}
</style>
<title>无标题文档</title>
<script>
function animate(obj,css,time,callbreak) {
var fps = 1000/60;
var tsp = Math.round(time/fps);
var tse = 0;
var yp = {};
var pi = {};
var sty = obj.currentStyle || getComputedStyle(obj,null);
for (var n in css){
css[n] = parseFloat(css[n]);
yp[n] = parseFloat(sty[n]);
pi[n] = sty[n].replace(/^[\-\d\.]+/,"");
}
var timer = setInterval(function(){
if (++tse > tsp) {
clearInterval(timer);
callbreak && callbreak();
return;
}
for (var n in css)
obj.style[n] = yp[n]+(css[n]-yp[n])*(tse/tsp) + pi[n];
}, fps);
return timer;
}
window.onload = function() {
var oDiv1 = document.getElementById('div1');
var oDiv2 = document.getElementById('div2');
var oDiv3 = document.getElementById('div3');
function loop() {
animate(oDiv1,{width:500,height:500},5000,function () {
animate(oDiv1,{left:500,top:500,width:0,height:0},5000,function () {
animate(oDiv2,{left:0,top:0,width:500,height:500},5000,function () {
animate(oDiv2,{width:0,height:0},5000,function () {
animate(oDiv3,{width:500,height:500},5000,function () {
animate(oDiv3,{left:500,top:500,width:0,height:0},5000,function () {
oDiv1.style.left = "0px";
oDiv1.style.top = "0px";
oDiv2.style.left = "500px";
oDiv2.style.top = "500px";
oDiv3.style.left = "0px";
oDiv3.style.top = "0px";
loop();
});
});
});
});
});
});
}
loop();
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</htm>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<style type="text/css">
#div1{width:0px; height:0px; background:#CCC; position:absolute; left:0px; top:0px;}
#div2{width:0px; height:0px; background:#000; position:absolute; left:500px; top:500px;}
#div3{width:0px; height:0px; background:#ff0; position:absolute; left:0px; top:0px;}
</style>
<title>无标题文档</title>
<script>
function animate(obj,css,time,callbreak) {
var fps = 1000/60;
var tsp = Math.round(time/fps);
var tse = 0;
var yp = {};
var pi = {};
var sty = (obj.currentStyle||getComputedStyle(obj,null));
for (var n in css){
css[n] = parseFloat(css[n]);
yp[n] = parseFloat(sty[n]);
pi[n] = sty[n].replace(/^[\-\d\.]+/,"");
}
var timer = setInterval(function(){
if (++tse > tsp) {
clearInterval(timer);
callbreak && callbreak();
return;
}
for (var n in css)
obj.style[n] = yp[n]+(css[n]-yp[n])*(tse/tsp) + pi[n];
}, fps);
return timer;
}
window.onload = function() {
var oDiv1 = document.getElementById('div1');
var oDiv2 = document.getElementById('div2');
var oDiv3 = document.getElementById('div3');
animate(oDiv1,{width:500,height:500},5000,function () {
animate(oDiv1,{left:500,top:500,width:0,height:0},5000,function () {
animate(oDiv2,{left:0,top:0,width:500,height:500},5000,function () {
animate(oDiv2,{width:0,height:0},5000,function () {
animate(oDiv3,{width:500,height:500},5000,function () {
animate(oDiv3,{left:500,top:500,width:0,height:0},5000,function () {
});
});
});
});
});
});
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</htm>