100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html小球跳跃技术原理 弹跳的小球.html · web-project-songyu/原生js小例子 - Gitee.com...

html小球跳跃技术原理 弹跳的小球.html · web-project-songyu/原生js小例子 - Gitee.com...

时间:2019-11-28 16:13:33

相关推荐

html小球跳跃技术原理 弹跳的小球.html · web-project-songyu/原生js小例子 - Gitee.com...

Document

#ball {

border-radius: 50%;

position: absolute;

}

var ball = document.getElementById("ball");

var a = { x: 100, y: 50, r: 25, w: 4, h: 5, g: 2, color: "red" }

ball.style.left = a.x + "px";//初始位置

ball.style.top = a.y + "px";

ball.style.width = a.r * 2 + "px";//球的参数

ball.style.height = a.r * 2 + "px";

ball.style.background = a.color;//颜色

var time = setInterval(function () {

a.x += a.w; //移动距离

a.y += a.h;

a.h += a.g; //掉落加速

ball.style.top = a.y + "px";

ball.style.left = a.x + "px";

if (a.y > 500) {//漂移+回弹

a.h = -a.h * 0.8;

}

}, 50);

一键复制

编辑

Web IDE

原始数据

按行查看

历史

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。