这是我目前的进展:
我正在尝试向这个示例中添加多个div,以便每个div都可以独立地在黑色框中弹跳。理想情况下,每个单词也应该有一个独特的起始位置(不仅仅是在左上角)。
这是我目前的进展:
var vx = 3;
var vy = 2;
function hitLR(el, bounding) {
if (el.offsetLeft <= 0 && vx < 0) {
console.log('LEFT');
vx = -1 * vx;
}
if ((el.offsetLeft + el.offsetWidth) >= bounding.offsetWidth) {
console.log('RIGHT');
vx = -1 * vx;
}
if (el.offsetTop <= 0 && vy < 0) {
console.log('TOP');
vy = -1 * vy;
}
if ((el.offsetTop + el.offsetHeight) >= bounding.offsetHeight) {
console.log('BOTTOM');
vy = -1 * vy;
}
}
function mover(el, bounding) {
hitLR(el, bounding);
el.style.left = el.offsetLeft + vx + 'px';
el.style.top = el.offsetTop + vy + 'px';
setTimeout(function() {
mover(el, bounding);
}, 50);
}
setTimeout(function() {
mover($('.bouncer')[0], $('.bouncyHouse')[0]);
}, 50);
我正在尝试向这个示例中添加多个div,以便每个div都可以独立地在黑色框中弹跳。理想情况下,每个单词也应该有一个独特的起始位置(不仅仅是在左上角)。