Skip to content

Instantly share code, notes, and snippets.

@abteilung
Created May 20, 2013 18:47
Show Gist options
  • Save abteilung/5614355 to your computer and use it in GitHub Desktop.
Save abteilung/5614355 to your computer and use it in GitHub Desktop.
Eyes following Mouse Pointer. Augen folgen der Maus
// JS-Code für die Augen
function jseyesmove(e, t, n) {
var r, i, s, o = $("#" + n),
u = $("#" + n + "_pupille"),
a = o.position();
i = e - a.left - 10;
s = t - a.top - 10;
r = i * i / 90 + s * s / 110 < 1 ? 1 : Math.sqrt(9900 / (i * i * 110 + s * s * 90));
u.css("left", r * i + 10 + "px");
u.css("top", r * s + 10 + "px")
}
$(document).ready(function () {
$(document).mousemove(function (e) {
jseyesmove(e.pageX, e.pageY, "auge");
jseyesmove(e.pageX, e.pageY, "auge2")
});
});
/*
<!-- HTML-code für die Augen -->
<div id="auge">
<div id="auge_pupille">
<img width="8" height="8" src="img/pupille.png" alt="Pupille" />
</div>
</div>
<div id="auge2">
<div id="auge2_pupille">
<img width="8" height="8" src="img/pupille.png" alt="Pupille" />
</div>
</div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment