Bläddra i källkod

Preset eye position

Danilo Gómez Gómez 4 år sedan
förälder
incheckning
844a03984e
1 ändrade filer med 20 tillägg och 0 borttagningar
  1. 20 0
      static/js/eye.js

+ 20 - 0
static/js/eye.js

@@ -16,8 +16,28 @@ window.onload = function () {
     const pend = 17;
     const plength = pend - pstart;
     const oY = logo.getAttribute('height') / 2.;
+    var firstTime = true;
+    var x0 = -1;
+    var y0 = -1;
+
+    // preinitialize eye position (it could be never updated)
+    const r = .9;//(ev.clientX) / (window.innerWidth) / 2 + .5;
+
+    const iX = istart + ilength * r;
+    iris.setAttribute('cx', iX);
+
+    const pX = iX + pstart + plength * r;
+    pupil.setAttribute('cx', pX);
+    pupil.setAttribute('cy', oY);
 
     window.onmousemove = function (ev) {
+        if (firstTime) {
+            x0 = ev.clientX;
+            y0 = ev.clientY;
+            firstTime = false;
+            return;
+        }
+        if (ev.clientX == x0 && ev.clientY == y0) return; // avoid fake mouse data (Safari et all)
         const eyeOffset = body.getBoundingClientRect().x + lang.clientWidth + eye.clientWidth / 2;
         const r = (ev.clientX - eyeOffset) / (window.innerWidth - eyeOffset) / 2 + .5;
         const ry = ev.clientY / window.innerHeight;