javascript - Restart transition effect using js or jquery
问题描述
I'm making a game that uses transitions that are similar to those in 2048. In 2048, when a player spam clicks fast, previous transitions will all end and then the new ones start.
function a(){
//do this without any transition
document.getElementById("di").style.width = "100px";
//do this with transition
document.getElementById("di").style.width = "300px";
//goal: every click, reset the width without any transition and start again, without timeouts
}
#di {
width: 100px;
height: 100px;
background: red;
transition: width 10s;
}
<h1 id="qwe" onclick="a()">Start</h1>
<div id="di"></div>
The comments in the function a() tell you what i want. basically, i want the rectangle to go back to 100px (instantly) and then start the transition again.
I do not want any timeouts because the real scenario is quite a bit more complicated and cant have delays
also, I know about css animations, but in the real scenario, they won't work
解决方案
So if using jQuery,
function a()
{
$("#di").css("width", "100px");
$("#di").animate({width: "300px"});
}
and without transition
property in CSS.
推荐阅读
- java - 如何使用 JNA 确定 Java 中的 Windows 进程位数?
- r - 多项式回归图和“newdata”错误
- javascript - 我可以从对象中获取一些键值吗?
- swift - FirebaseCore 词法或预处理器问题
- symfony4 - 每个环境的自定义原则配置
- python - 使用运算符 python 在另一个字符串中找不到从正则表达式返回的字符串
- c# - 修改 Visual Studio/Dot Net 如何创建 DLL?
- ssas - MDX 查询以计算产品名称的数量
- python - 使用 pandas 检查条件时排除某些值
- python - 通过 AWS-IoT Core 连接时无法更改 RaspberryPi 上的主题名称