我的目标:在效果发生时按住空格键(模拟指纹扫描)。如果用户在效果完成之前释放键,我想显示一条确认消息。keydown 部分工作正常并继续执行“处理”功能,但如果在效果完成之前释放它,则不会在 keyup 上显示错误消息。这就是我所拥有的...
var active = false;
$(document).one("keydown", function(e) {
if ((e.keyCode == 32) && (active == false)) {
active = true;
$(".panel_1").slideDown(5000, function() {
active = false;
$(".panel_1").slideUp(2000, function() {process(); })
});
}
});
$(document).one("keyup",function(e) {
if ((e.keyCode == 32) && (active == true)) {
var r=confirm("Oops! You must HOLD down the space key until scan is complete. Press OK to try again, or Cancel to return to homepage.");
if (r==true) {
reset();
}
else {
window.location.replace("home.html");
}
}
});