【发布时间】:2020-08-08 15:29:08
【问题描述】:
我正在尝试更改图像的变换属性,使其在起始位置和函数更改的新位置之间来回摆动。它运行一次然后停留在那里,我假设它是因为我没有指定如何或何时返回。任何帮助表示赞赏。这是我的 JS 代码
function moveHands() {
var handLeft = document.getElementById("metalHand2");
var handRight = document.getElementById("metalHand");
handLeft.style.transform = "translateX(12px) scaleX(-1)";
handRight.style.transform = "translateX(12px)";
setTimeout(moveHands, 1283.42);
}
document.getElementById("playBtn").addEventListener("click", moveHands);
这是我的 HTML
<div id="flexBox2">
<div id="picContainer">
<img src="hand.jpg" alt="metal hand" id="metalHand">
</div>
<div id="picContainer2">
<img src="hand.jpg" alt="metal hand" id="metalHand2">
</div>
</div>
<input type="button" value="Play" id="playBtn">
【问题讨论】:
-
使用 css 过渡
-
请出示您的按钮代码playBtn
-
以什么方式?我只是错过了转换属性,还是您说用 setTimeout 函数替换它。还添加了按钮 ty
标签: javascript html set settimeout intervals