我正在努力使这个示例难题。我想改变方向,如果拼图触摸底部窗口,那么它将沿着右侧窗口像以前一样旋转,再次触摸右侧窗口后,它将移动到顶部窗口
let delayInSecond = 1000; //1 second
let squireElem = document.querySelector('.squire');
let maxHeight = window.innerHeight;
let posTop = 50;
let posRight = 0;
let posBottom = 0;
let posLeft = 0;
let timer = setInterval(squire, delayInSecond);
function squire() {
let elemHeight = squireElem.offsetHeight;
if (maxHeight === elemHeight) {
clearInterval(timer);
} else {
posTop += 10;
posRight += 10;
posBottom += 10;
posLeft += 10;
squireElem.style.top = posTop + 'px';
squireElem.style.left = posLeft + 'px';
}
}
* {
margin: 0;
padding: 0;
}
.squire {
width: 100px;
height: 100px;
background-color: blue;
position: absolute;
top: 50px;
}
<div class="squire"></div>
相关分类