[英]Initial Delay for Event(mousedown)?
<!DOCTYPE html>
<html onmouseup="end()">
<head>
<meta charset="UTF-8">
<script type="text/javascript">
var counter;
var count = 0;
function start(outp)
{
counter = setInterval(function()
{
console.log(count);
add(outp);
count++;
},500);
}
function end()
{
clearInterval(counter);
}
function add(outp)
{
window.document.form1.Display.value =
window.document.form1.Display.value + outp;
}
</script>
</head>
<body >
<form name="form1">
<button onmousedown="start('x')"onmouseleave="end()" >Click and hold</button>
<input type="text"name="Display"class="display"readonly>
</form>
</body>
</html>
Thats the snippet, the "500" is the delay between each iteration but I have no Idea how to specify the initial delay.这就是片段,“500”是每次迭代之间的延迟,但我不知道如何指定初始延迟。
The button normally also has an Onclick event and I want the onmouse event to be triggered after X amount of time.该按钮通常还有一个 Onclick 事件,我希望在 X 时间后触发 onmouse 事件。
Try setting an initial timeout and doing your logic in there, and then also setting the interval with the same logic.尝试设置初始超时并在那里执行您的逻辑,然后还使用相同的逻辑设置间隔。
setTimeout(() => {
console.log(count);
add(outp);
count++;
counter = setInterval(() =>
{
console.log(count);
add(outp);
count++;
}, 500);
}, initialTimoutMs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.