eye.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. window.onload = function () {
  2. const body = document.getElementById('body');
  3. const lang = document.getElementById('lang-chooser');
  4. const eye = document.getElementById('logo');
  5. const logo = document.getElementById('alucho-logo');
  6. const iris = document.getElementById('iris');
  7. const pupil = document.getElementById('pupil');
  8. // #iris cx attribute animation settings (relative to #alucho-logo i.e. absolute inside the svg)
  9. const istart = 66;
  10. const iend = 126;
  11. const ilength = iend - istart;
  12. // #pupil cx attribute animation settings (relative to #iris cx)
  13. const pstart = -17;
  14. const pend = 17;
  15. const plength = pend - pstart;
  16. const oY = logo.getAttribute('height') / 2.;
  17. window.onmousemove = function (ev) {
  18. const eyeOffset = body.getBoundingClientRect().x + lang.clientWidth + eye.clientWidth / 2;
  19. const r = (ev.clientX - eyeOffset) / (window.innerWidth - eyeOffset) / 2 + .5;
  20. const ry = ev.clientY / window.innerHeight;
  21. const iX = istart + ilength * r;
  22. iris.setAttribute('cx', iX);
  23. const pX = iX + pstart + plength * r;
  24. const pY = oY + 20 * r * (1 - r) * ry;
  25. // p(r) = y0 + a * r * (1 - r) is a parabola
  26. // p(0) = p(1) = y0
  27. // p(.5) = y0 + a / 4
  28. pupil.setAttribute('cx', pX);
  29. pupil.setAttribute('cy', pY);
  30. };
  31. };