【发布时间】:2020-09-09 13:13:45
【问题描述】:
我想沿特定路径移动箭头。我知道我必须应用 CSS translate 来移动箭头,但我遇到了一个问题。
箭头需要向下移动,然后向左移动,然后向上移动,直到它从它开始的位置到达同一水平平原,但在其初始位置的左侧。
我可以把它往下移,这是第一步。但是如果我使用所有三种翻译方法,它会直接将其带到最终位置而不跟随路径。我尝试将三个 translate 方法及其转换放入单独的函数中,并在上一步结束时调用每个函数,但结果相同。
这是 HTML:
<div>
<img src="img/arwTest.png" alt="Click to rotate" id="arrow">
<img src="img/moveTest_2.png" alt="demonstration" id="demo">
<p>Click anywhere to move the arrow along the path.</p>
</div>
这是 CSS:
#demo, #arrow {
display: block;
margin: 0 auto;
}
#demo {
height: 300px;
}
#arrow {
height: 40px;
position: absolute;
left: 50%;
}
p {
text-align: center;
padding: 20px;
}
这是 JavaScript:
const arrow = document.getElementById("arrow");
arrow.style.transform = `rotate(90deg)`;
addEventListener('click', () => {
arrow.style.transform = `translate(0px,200px)`;
arrow.style.transition = `2s`;
})
Here's 整件事。
【问题讨论】:
-
将您的代码作为minimal reproducible example发布在问题中
标签: javascript html css dom css-transitions