eye.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // nilox (c)
  2. window.onload = function () {
  3. var eye = document.getElementById('logo');
  4. var eyeDoc = eye.contentDocument;
  5. const logo = eyeDoc.getElementById('alucho-logo');
  6. const iris = eyeDoc.getElementById('iris');
  7. const pupil = eyeDoc.getElementById('pupil');
  8. // #iris cx attribute animation settings (relative to #alucho-logo i.e. absolute inside the svg)
  9. const istart = 56;
  10. const iend = 116;
  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 r = ev.clientX / window.innerWidth;
  19. const iX = istart + ilength * r;
  20. iris.setAttribute('cx', iX);
  21. const pX = iX + pstart + plength * r;
  22. const pY = oY + 16 * r * (1 - r);
  23. // p(r) = y0 + a * r * (1 - r) is a parabola
  24. // p(0) = p(1) = y0
  25. // p(.5) = y0 + a / 4
  26. pupil.setAttribute('cx', pX);
  27. pupil.setAttribute('cy', pY);
  28. };
  29. };