87,993
社区成员
发帖
与我相关
我的任务
分享
var cc = document.getElementById("cc"), oW = 200, oH = 200;//对象长宽
var cW = document.documentElement.clientWidth, cH = document.documentElement.clientHeight;//视窗长宽
var cRight = Math.ceil((cW - oW) / 2), cBottom = Math.ceil((cH - oH) / 2);//计算对象移动到中间时的bottom/right
var hStep = 5, vStep = hStep * cBottom / cRight;//水平每次移动5px,等比计算垂直移动的距离
var timer, bottom = 0, right = 0;
setTimeout(function () {
cc.style.display = 'block'
timer = setInterval(function () {
right += hStep; bottom += vStep;
cc.style.right = right + "px";
cc.style.bottom = bottom + "px";
if (right > cRight) {//到中间翻转
hStep = -hStep;
vStep = -vStep;
}
if (right == 0 || bottom == 0) {
clearInterval(timer)
cc.style.display = 'none'
}
},10)
}, 3000);