eye.js 1.3 KB

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