连续运行功能,需要计数动作

Continously running function, need to count actions

本文关键字:运行 功能 连续      更新时间:2023-09-26

我正在使用眼动追踪,我正在尝试计算用户在屏幕上查看特定位置的次数。问题是,当用户盯着某个指定区域时,它会一直计数,直到用户把目光移开。有没有办法设置一个超时函数或防止函数计数连续?

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";               
        };
    }
});

}

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