-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgazelistener.js
67 lines (64 loc) · 2.09 KB
/
gazelistener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var elements = [];
var hasBeenOver = []
var hasLeft = new Set();
var counter = 0;
var buffer = 20;
function addElement(id){
elements.push(id);
}
console.log(elements);
function isOverListener()
{
var prediction = webgazer.getCurrentPrediction();
if (prediction)
{
console.log("hello");
let x = prediction.x;
let y = prediction.y;
console.log("x:"+x);
console.log("y:"+y);
hasBeenOver[counter] = null;
elements.forEach(function(id){
ele = document.getElementById(id);
let eleStyle = window.getComputedStyle(ele);
let widthStr = eleStyle.width.toString();
console.log(widthStr);
let width = parseInt(widthStr.substring(0,widthStr.length - 2)) + buffer;
let heightStr = eleStyle.height.toString();
let height = parseInt(heightStr.substring(0,heightStr.length-2)) + buffer;
let topStr = eleStyle.top.toString();
let top = parseInt(topStr.substring(0,topStr.length-2)) - buffer;
let leftStr = eleStyle.left.toString();
let left = parseInt(leftStr.substring(0,leftStr.length-2)) - buffer;
console.log("left: "+left+"top:"+top+"height: "+height+"width: "+width);
let inside = x > left && y > top && y < top+height && x < left + width;
//console.log(inside);
if(inside)
{
if(hasBeenOver.includes(id))
{
ele.classList.add("hover");
console.log("yeet");
}
else
{
hasBeenOver[counter] = id;
}
}
else
{
if(hasLeft.has(id))
{
hasLeft.delete(id)
ele.classList.remove("hover");
}
else
{
hasLeft.add(id);
}
}
});
counter= counter + 1 % 10;
}
}
window.setInterval(isOverListener, 200);