function PosNav(e) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } // posx and posy contain the mouse position relative to the document // Do something with this information var NavDiv = document.getElementById('mainnav'); var navX = posx - 150; var navY = posy - 150; NavDiv.style.top = navY.toString() + "px"; NavDiv.style.left = navX.toString() + "px"; } // Þessi function á að kalla á PosNav þegar það er klikkað á (held ég) function doPosNav() { document.onclick = function(){ PosNav(); return false; } } window.onload = doPosNav(this);
Getur einhver hjápað?