gpt4 book ai didi

javascript - 连续运行的函数,需要计数 Action

转载 作者:行者123 更新时间:2023-12-03 06:13:36 28 4
gpt4 key购买 nike

我正在使用眼动追踪,并尝试计算用户查看屏幕上特定位置的次数。问题是,当用户正在查看指定区域之一时,它将一直计数,直到用户将目光移开为止。有什么办法可以设置超时功能或者阻止该功能连续计数吗?

function onGazePoint(gazePoint) {

latestGazePoint = gazePoint;

overwolf.windows.getCurrentWindow(function(result) {
if (result.status == "success") {
if (isGazePointWithinWindow(result.window, gazePoint)) {
document.getElementById("content").style.opacity = "1.0";
/*var hotspot = ;*/
var hotspotNum = document.getElementById('content').getAttribute('data-value');
/*document.getElementById("hotspotnr").innerHTML = hotspotNum; */
console.log(hotspotNum);
var hotspot = 0;
switch(hotspotNum) {
case '1':
document.getElementById("numberOfLooks").innerHTML = maplooks++;
break;
case '2':
document.getElementById("numberOfLooks").innerHTML = hotspotNum;
break;
case '3':
document.getElementById("numberOfLooks").innerHTML = hotspotNum;
break;
case '4':
document.getElementById("numberOfLooks").innerHTML = hotspotNum;
break;
default:
console.log(new Date().getTime(), hotspotNum);
}
}
else {
document.getElementById("content").style.opacity = "0.4";
};
}
});

}

最佳答案

要解决计数问题,您必须使用 bool 变量作为信号量。例如,您将其值设置为 false,并且当用户第一次查看该区域时,您将值设置为 true 并计数 1。然后,直到标志值为 true,您将停止计数,当用户停止查看该区域时,您将重置标志为假。

关于javascript - 连续运行的函数,需要计数 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39210007/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com