codigo de Ojos que siguen al cursor IV




Diseño | Elementos de la página | Añadir gadget | HTML/Javascript. Y si usas la nueva interfaz entra en Diseño | Añadir gadget | HTML/Javascript. Ahí pega esto:


<script type='text/javascript'>
//<![CDATA[
// Ojos que siguen al cursor
// Script original de Oopstudios.com
// Adaptado por ciudadblogger.com

EYES = {};
EYES.stack = [];
//
EYES.follow = function (eye) {
var el1 = document.getElementById (eye);
var el2 = el1.getElementsByTagName ("IMG");
el2 = el2[0];
el2.centre = (el1.offsetWidth - el2.offsetWidth) / 2;
el2.style.margin = el2.centre + "px 0 0 " + el2.centre + "px";
el1.maxDist = 6 * el1.offsetWidth;
EYES.stack.push ([el1, el2]);
};
EYES.mousemove = function (e) {
if (!EYES.stack.length) {
return;
}
//
var mouseX = mouseY = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
mouseX = e.pageX;
mouseY = e.pageY;
} else if (e.clientX || e.clientY) {
mouseX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
mouseY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
//

for (var e=0, l=EYES.stack.length; e<l; e++) {
var el = EYES.stack[e];
var elX = elY = 0;
if (el[0].offsetParent) {
obj = el[0];
do {
elX += obj.offsetLeft;
elY += obj.offsetTop;
} while (obj = obj.offsetParent);
}
el[0].centreX = elX + Math.round (el[0].offsetWidth / 2);
el[0].centreY = elY + Math.round (el[0].offsetHeight / 2);
var difX = mouseX - el[0].centreX;
var difY = mouseY - el[0].centreY;
var dTan = Math.atan2 (difX, difY);
var dist = Math.sqrt ((difX * difX) + (difY * difY));
dist = Math.sin ((dist > el[0].maxDist ? 1 : dist / el[0].maxDist));
var newX = el[1].centre + Math.round (Math.sin (dTan) * el[1].centre * dist);
var newY = el[1].centre + Math.round (Math.cos (dTan) * el[1].centre * dist);
el[1].style.margin = newY + "px 0 0 " + newX + "px";
}
};

if (window.attachEvent) document.attachEvent ("onmousemove", EYES.mousemove);
else document.addEventListener ("mousemove", EYES.mousemove, false);
//]]>
</script>


<div style="position:relative; height:161px; margin-bottom:30px;">
<div id="Ojo1" style="width: 180px; height: 161px; background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO81REEsd4nht9LAiJk_HE4XM3uF1edDgEnQ0PSRA2aChH8zrwl3jHPghhI7tUCTuc2xrRyvSk7yXNT-CRvgjVCt87xPv5xf8BwoJLmImjby6R-fOYtNyGWxKtZGulrSoF9-CZnYLx170/s180/ojo1.png) center center no-repeat; position:absolute; left: 307px; top: 20px;">
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivVWE60a0313rMSx2Wlmng5d8zbsnl51H2E_lQfV569YuoCVwatmdqwto_MXYbRCBbdwTJvf50Pbi2MziPdzVn1AMYbDQQC5cf0cQJCQXB6wDINqOC4TqOo0ATI4KPanLQV2SHrw41ORY/s71/pupila.png" width="65" height="65" /></div>
<div id="Ojo2" style="width: 180px; height: 161px; background: url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwLJg9XHJR-kfVhlZaWtskU_iqqE-zMaXQ0eZz5due8dSzL9sFqwY7bIqG15AruO1KAr2IMhXzY5l8DERubhtw7zCdHNhk-nGRf9AmKIdtEHPInYaamF6ZAIgaK9q7bEO8xPiVRK-21zQ/s180/ojo2.png) center center no-repeat; position:absolute; left: 545px; top: 20px;">
<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivVWE60a0313rMSx2Wlmng5d8zbsnl51H2E_lQfV569YuoCVwatmdqwto_MXYbRCBbdwTJvf50Pbi2MziPdzVn1AMYbDQQC5cf0cQJCQXB6wDINqOC4TqOo0ATI4KPanLQV2SHrw41ORY/s71/pupila.png" width="65" height="65" /></div>
</div>

<script type="text/javascript">
EYES.follow ('Ojo1');
EYES.follow ('Ojo2');
</script>